开发者

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

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/P开发者_开发知识库age1

or http://localhost:1103/Page2

thanks


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜