views:

133

answers:

1

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

+1  A: 

Remove the List() controller method. In the book, it states that you needed to update the existing List() method to the the one you currently have List(int page).

Ahmad