Is there a way to override the action of MVC Controller?

I am adapting an open source project (NopCommerce). It is great software and supports extensibility with plugins. For one plugin, I would like to add information to the view, to do this, I want to inherit from the controller and override the actions I need to change. So this is my controller:

public class MyController : OldController{
//stuff

public new ActionResult Product(int productId)
{
 //Somestuff
}

}

I changed the route from my plugin, but when this action succeeds, I get the following error:

The current request for the Product action for the MyController controller type is ambiguous between the following action methods: System.Web.Mvc.ActionResult Product (Int32) as MyPlugin System.Web.Mvc.ActionResult Product (Int32) as OldController

- ? (ps: override, , OldController)

,

+5
1

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(...);
    }
}
+6

All Articles