【发布时间】:2013-08-21 16:11:39
【问题描述】:
我最近开始使用 MVC4,现在我开始使用部分视图。
我目前有一个这样的控制器:
public class BlogController : Controller
{
[ChildActionOnly]
public ActionResult MostRecent()
{
...
}
}
然后我使用以下行从我的任何一种观点中调用它:
@{ Html.RenderAction("MostRecent", "Blog"); }
是否可以这样做:
public static class PartialHelper
{
public static string RenderMostRecent()
{
return notsurewhat.RenderAction("MostPopular", "Blog");
}
}
所以在我的代码中我只需要调用:
@PartialHelper.RenderMostRecent()
这样我可以随时更改控制器/操作,而不必在调用该局部视图的所有地方进行更新。
如果有更简单的方法,欢迎提出想法!
谢谢
【问题讨论】:
标签: c# asp.net-mvc-4 renderaction