asp.net-mvc - Umbraco 表面 Controller 或 RenderMvcController

标签 asp.net-mvc umbraco

嗨,我在 umbraco 7 中有一个“home” Controller 和一个“sort” Controller 。“home” Controller 对于索引操作工作得很好,因为它被 RenderMvcController 覆盖。首先,我很困惑应该在哪个实例中使用哪个 Controller ,即表面 Controller 或 rendermvccontroller。我似乎无法访问下面的 Twitter 操作,这是我需要 ajax 的东西。我是否需要将 twitter 操作放入 Surface Controller 中,或者我可以在 umbraco 中使用常规 MVC Controller 吗?

     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));
    }

最佳答案

我的方法是:

  • 渲染 Controller 仅用于向用户显示数据。
  • Surface Controller 用于交互(我主要使用它进行交互,主要是 ajax 或表单)

要渲染子操作,您可以使用以下示例:

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

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

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

关于asp.net-mvc - Umbraco 表面 Controller 或 RenderMvcController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21971399/

相关文章:

asp.net-mvc - ASP.net Web API和System.Net.Http

asp.net-mvc - 从另一个 View 渲染部分 View (使用 Controller 操作)

asp.net-mvc - xVal 和 ASP.Net MVC 2 AddModelStateErrors 问题

c# - Umbraco 检查节点是否仍然存在

c# - Umbraco RelationService.GetByParentId(memberId) 慢。每个项目触发两个查询

asp.net - 是否需要授予应用程序池身份对Web文件夹的读取权限?

asp.net-mvc - 如何使用 WebSecurity + SimpleMembership 手动设置 "log a user in"?

azure - 在 Azure 应用服务上将 Umbraco 更新到最新版本

umbraco - umbraco 4 中的文件夹

UmbracoLog 表