0
我最近开始玩MVC4,现在我正在接受部分视图。Html.RenderAction作为静态方法
我现在有一个控制器,像这样:
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()
这样我就可以在任何时候更改控制器/操作,而且我无需在任何地方更新即可调用该局部视图。
如果有一个更简单的方法来做到这一点,打开想法!
感谢
真棒!使这项工作唯一需要的是将第一个参数改为'this HtmlHelper html',以使其成为扩展方法。非常感谢! – seanxe
你是对的。我忘了那个。答案已更新。 –