The action of the controller is ambiguous between the actions of the base layer with the same name.

The current index action request for a ContactController controller ContactController ambiguous between the following methods:

 System.Web.Mvc.ActionResult Index() on type RX.Web.Controllers.ContactController System.Web.Mvc.ActionResult Index() on type RX.Web.Controllers.CustomControllerBase2[[RX.Core.Model.Contact, RXTechJob.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] 

Contact Controller:

  public virtual new ActionResult Index() { return base.Index(); } 

Base controller:

  public virtual ActionResult Index() { return View("Index", SelectAll()); } 

Why is this happening? How to fix it? Thanks!

+6
c # asp.net-mvc
source share
2 answers

You create a second method, called an index, that MVC does not know how to handle. see here for a discussion of virtual new creating an additional non-overriding method.

Instead, for your contact controller, consider something along the line:

 public override ActionResult Index() { return base.Index(); } 
+5
source share

Thanks for your reply.

Since stackoverflow did not recognize my Gooogle OpenID, so I create a new account and come back again :)

I cannot use override because I use T4MVC .

So, I will fix it like this:

base controller (replace "public" with "protected"):

  protected virtual ActionResult Index() { return View("Index", SelectAll()); } 

contact controller:

  public virtual new ActionResult Index() { return base.Index(); } 

In the automatically generated T4MVC code, you can override it:

  public override System.Web.Mvc.ActionResult Index() { var callInfo = new T4MVC_ActionResult(Area, Name, Actions.Index); return callInfo; } 

Everything seems to be working fine now. :)

0
source share

All Articles