JSB*_*ach 5 c# asp.net nopcommerce asp.net-mvc-4
我正在调整一个开源项目(NopCommerce).它是一款出色的软件,支持使用插件进行扩展.对于一个插件,我想向视图添加信息,为此,我想从Controller继承并覆盖我需要更改的操作.所以这是我的控制器:
public class MyController : OldController{
//stuff
public new ActionResult Product(int productId)
{
//Somestuff
}
}
Run Code Online (Sandbox Code Playgroud)
我从我的插件更改了路由,但是当调用此操作时,我收到以下错误:
控制器类型'MyController'上的当前操作'Product'请求在以下操作方法之间是不明确的:System.Web.Mvc.ActionResult类型MyPlugin上的产品(Int32)System.Web.Mvc.ActionResult类型OldController上的产品(Int32)
有什么办法可以覆盖这个方法吗?(ps:我不能使用override关键字,因为它在OldController中没有标记为虚拟,抽象或覆盖)
谢谢,奥斯卡
如果OldController的方法很少,Redeclare就像这样.
public class MyController : Controller
{
private OldController old = new OldController();
// OldController method we want to "override"
public ActionResult Product(int productid)
{
...
return View(...);
}
// Other OldController method for which we want the "inherited" behavior
public ActionResult Method1(...)
{
return old.Method1(...);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3906 次 |
| 最近记录: |