【问题标题】:Umbraco Surface Controller or RenderMvcControllerUmbraco 表面控制器或 RenderMvcController
【发布时间】:2014-02-23 17:04:24
【问题描述】:

嗨,我在 umbraco 7 中有我的“home”控制器和一个“sort”控制器。“home”控制器适用于 index 操作,因为它被 RenderMvcController 覆盖。首先,我很困惑我应该在哪个实例中使用哪个控制器,即表面控制器或 rendermvccontroller。我似乎无法访问下面的 twitter 操作,这是我需要 ajax 的东西。我需要将 twitter 操作放在表面控制器中还是可以在 umbraco 中使用常规的 mvc 控制器?

     public override ActionResult Index(RenderModel model)


       {
            var storedProcedure = new StoredProcedure()
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["CentralDbContext"].ConnectionString
            };

            DataSet ds = storedProcedure.ExecuteProcedureToDataSet("GetHomePage");

            IMapSetup map = new MapHomePage();
            HomePage homepage = map.Setup<HomePage>(ds);


            homepage.Slideshow = CurrentPage.AncestorsOrSelf(1).First().Descendants("SlideshowItem").Take(5).AsMany<Slideshow>();

            this._weatherSettings.DefaultLocation = "warrington";
            homepage.Forecast = new Forecaster(this._weatherSettings, this._cacheHelper).GetWeather(this._weatherSettings.DefaultLocation);

            return CurrentTemplate(homepage);
        }
 public ActionResult TwitterSort(int? page)
    {
        int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

        var storedProcedure = new StoredProcedure()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["CentralDbContext"].ConnectionString
        };

        DataSet ds = storedProcedure.ExecuteProcedureToDataSet("GetHomePage");

        IMapSetup map = new MapHomePage();
        HomePage homepage = map.Setup<HomePage>(ds);


        if (Request.IsAjaxRequest())
        {
            return PartialView("umbTweets", homepage.Twitter.ToPagedList(currentPageIndex, DefaultPageSize));
        }

        return PartialView(homepage.Twitter.ToPagedList(currentPageIndex, DefaultPageSize));
    }

【问题讨论】:

    标签: asp.net-mvc umbraco


    【解决方案1】:

    我的方法是:

    • 渲染控制器仅用于向用户显示数据。
    • 表面控制器用于交互(我主要用它来交互 ajax 或表单)

    对于渲染子动作,您可以使用以下示例:

    http://our.umbraco.org/documentation/Reference/Mvc/child-actions

    更新: 要实现自定义路由,您可以查看

    http://cpodesign.com/blog/umbraco-implementing-routing-in-mvc/

    【讨论】:

    • 我可以更改表面控制器在 umbraco 中使用的默认路径吗,我不希望我的主页在 url 中是 /umbraco/surface - 我可以使用表面控制器更新传递给视图的模型吗太
    • @MatthewChambers 检查更新,是的,你可以,不,你不应该让所有东西都通过表面控制器运行(只有通信)
    • 不要忘记在 umbraco 的 web.config umbracoReservedPaths 中添加路径
    • @VinnyG 为什么要在保留路径中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多