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:
or
or http://localhost:1103/Page2
thanks