开发者

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

开发者 https://www.devze.com 2022-12-14 02:12 出处:网络
The current request for action \'Index\' on controller type ContactController is ambiguous between the following action methods:

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, PublicKeyT开发者_如何学编程oken=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!


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


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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消