嗨,我在 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/