Asp.net mvc 2 asp.net mvc 2:SportsStore应用程序:当前的操作请求不明确
我正在研究下一本书第4章中的SportsStore示例,我被卡住了 Pro Asp.net mvc框架 我得到以下错误: 控制器类型“ProductsController”上操作“List”的当前请求在以下操作方法之间不明确: WebUI.Controllers.ProductsController类型上的System.Web.Mvc.ViewResult List() WebUI.Controllers.ProductsController.类型上的System.Web.Mvc.ViewResult列表(Int32) 我的路由器代码如下所示:Asp.net mvc 2 asp.net mvc 2:SportsStore应用程序:当前的操作请求不明确,asp.net-mvc-2,Asp.net Mvc 2,我正在研究下一本书第4章中的SportsStore示例,我被卡住了 Pro Asp.net mvc框架 我得到以下错误: 控制器类型“ProductsController”上操作“List”的当前请求在以下操作方法之间不明确: WebUI.Controllers.ProductsController类型上的System.Web.Mvc.ViewResult List() WebUI.Controllers.ProductsController.类型上的System.Web.Mvc.ViewRes
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+" }
);
}
public ViewResult List()
{
return View(productsRepository.Products.ToList());
}
public ViewResult List(int page)
{
return View(productsRepository.Products
.Skip((page - 1) * PageSize)
.Take(PageSize)
.ToList());
}
控制器代码如下所示:
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+" }
);
}
public ViewResult List()
{
return View(productsRepository.Products.ToList());
}
public ViewResult List(int page)
{
return View(productsRepository.Products
.Skip((page - 1) * PageSize)
.Take(PageSize)
.ToList());
}
我错过了什么
我的网址如下:
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+" }
);
}
public ViewResult List()
{
return View(productsRepository.Products.ToList());
}
public ViewResult List(int page)
{
return View(productsRepository.Products
.Skip((page - 1) * PageSize)
.Take(PageSize)
.ToList());
}
或
或
谢谢删除列表()
控制器方法。在书中,它指出您需要将现有的List()
方法更新为您当前拥有的List(int page)