6

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!

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
Laurel.Wu
  • 146
  • 1
  • 5

2 Answers2

5

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();
}
Community
  • 1
  • 1
Michael Gattuso
  • 13,020
  • 2
  • 25
  • 29
0

Thanks for your answer.

Because stackoverflow did not recognise my Gooogle OpenID,so i create a new account and come back again :)

I can not use "override" because i am using T4MVC .

So i 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 T4MVC auto generated code it can be overrided:

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

Seemingly, everything works fine now. :)