Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The controller's action is ambiguous between the action of the baseclass with same name.

Tags:

c#

asp.net-mvc

The current request for action 'Index' on controller type ContactController is ambiguous between the following action 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]] 

The Contact Controller:

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

The base Controller:

        public virtual ActionResult Index()
    {

        return View("Index", SelectAll());

    }

Why this happen? How to fix it? Thanks!

like image 273
Laurel.Wu Avatar asked Dec 17 '09 10:12

Laurel.Wu


Video Answer


1 Answers

You are creating a second method called index that MVC does not know how to handle. see here for a discussion on virtual new creating an additional not overriding method.

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

public override ActionResult Index() {
        return base.Index();
}
like image 198
Michael Gattuso Avatar answered Oct 05 '22 18:10

Michael Gattuso