asp.net mvc 2: SportsStore application: The current request for action is ambiguous

Posted by dotnet-practitioner on Stack Overflow See other posts from Stack Overflow or by dotnet-practitioner
Published on 2010-05-19T12:53:19Z Indexed on 2010/05/19 13:00 UTC
Read the original article Hit count: 381

Filed under:
|

I am working on SportsStore example on chapter 4 from the following book and getting stuck...

Pro Asp.net mvc framework

I get the following error:

The current request for action 'List' on controller type 'ProductsController' is ambiguous between the following action methods: System.Web.Mvc.ViewResult List() on type WebUI.Controllers.ProductsController System.Web.Mvc.ViewResult List(Int32) on type WebUI.Controllers.ProductsController ..

My router code looks as follows:

        public static void RegisterRoutes(RouteCollection routes)
        {



            routes.MapRoute(
                null, // Route name
                "", // URL with parameters
                new { controller = "Products", action = "List", page=1 }
            );


            routes.MapRoute(
                null, // Route name
                "Page{page}", // URL with parameters
                new { controller = "Products", action = "List" }, // Parameter defaults
                new { page = @"\d+" }
            );
}

and controller code looks as follows:

public ViewResult List()
{
    return View(productsRepository.Products.ToList());
}

public ViewResult List(int page)
{
    return View(productsRepository.Products
                                .Skip((page - 1) * PageSize)
                                .Take(PageSize)
                                .ToList());
}

What am I missing?

my url is as follows:

http://localhost:1103/

or

http://localhost:1103/Page1

or http://localhost:1103/Page2

thanks

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc2