asp.net-mvcnerddinner

The current request for action 'Index' on controller type 'DinnersController' is ambiguous between the following action methods


I am getting this error after trying to implement paging support.

I am on this step of the html tutorial: http://nerddinnerbook.s3.amazonaws.com/Part8.htm


Solution

  • The error you are getting tells that ASP.NET MVC has found two actions with the same name and can't chose which to use.

    If you have two Index-actions in your DinnersController.cs:

    public ActionResult Index() {
    

    and:

    public ActionResult Index(int? page) {
    

    Then you should remove the first Action. since the second is the 'updated' version of the first. The second Action accepts requests to:

    /Dinners

    /Dinners?page=2

    /Dinners/Index

    /Dinners/Index?page=2

    And with the change in RegisterRoutes it also accepts requests to:

    /Dinners/Page/2

    You can have two Actions with the same name, providing one is for saving (postbacks), where you decorate the saving action with [AcceptVerbs(HttpVerbs.Post)] or just [HttpPost]