Umbraco Surface Controller或RenderMvcController

时间:2014-02-23 17:04:24

标签: asp.net-mvc umbraco

嗨,我有我的家'控制器和'排序' umbraco的控制器7.' home'控制器在从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));
    }

1 个答案:

答案 0 :(得分:5)

我的方法是:

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

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

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

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

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