【发布时间】:2015-12-07 11:04:12
【问题描述】:
旧:
public class HomeController : Controller {
public ActionResult Index()
{
// do something
return View();
}
}
我想扩展Index():
public static class HomeControllerExtensions{
public static ActionResult Index(this HomeController hc,string viewName)
{
// do something
return View(viewName);//hc.View cannot...., how to do return View()?
}}
如何返回View()?
【问题讨论】:
-
你到底想在这里做什么?我没有看到用例。
-
扩展方法也不扩展方法,它们扩展类(即它们向类伪添加附加方法)。
-
@Jonesopolis 我只想在“Index()”方法中添加一个参数,“Index()”方法根据显示返回视图的“viewName”。但是不能修改原来的方法
标签: c# asp.net asp.net-mvc extension-methods