Share via


why: Controller is ambiguous between the following action methods:

Question

Monday, November 26, 2012 10:59 AM

how can URL this be ambigous?

The current request for action 'index' on controller type 'CompanyController' is ambiguous between the following action methods:

http://localhost:50701/Company/index/1

public ViewResult Index(int id)
        {
            Company company = _companyProvider.Read(id);
            return View(company);
        }

        public ActionResult Index(Company company)
        {
            return View(company);
        }

All replies (5)

Monday, November 26, 2012 11:33 PM âś…Answered

GorillaMann

[HttpPost]
        public ActionResult Create(Company company, HttpPostedFileBase LogoFileName, CustomProfile customProfile)
        {

It is different from the one of the first post. did you recompile?


Monday, November 26, 2012 11:03 AM

The second , usually, have

[HttpPost]

attribute


Monday, November 26, 2012 11:11 AM

The first is a get,

The second one only gets called from a controller:

    [HttpPost]
        public ActionResult Create(Company company, HttpPostedFileBase LogoFileName, CustomProfile customProfile)
        {
            company.LogoFileName = SaveCompanyLogoImage(LogoFileName);
            company.CustomProfile = customProfile;
            Company newCompany = _companyProvider.Create(company);
            return View("Index", newCompany);
        }

Monday, November 26, 2012 11:21 AM

MVC only allows action method overload by http method (GET, HEAD, PUT, etc).  the controller action is picked by the route table, and if overloaded then by method. after selection of the action, the postback values are bound.


Tuesday, November 27, 2012 8:19 AM

yeah, this now works:

        [HttpGet]
        public ViewResult Index(int id)
        {
            Company company = _companyProvider.Read(id);
            return View(company);
        }

        public ActionResult Index(Company company)
        {
            return View(company);
        }