C# 改进asp.net mvc2中的URL
改进URL 目前我在表单中有链接(显示产品信息): 我想把它整理成以下表格: 我想我需要使用C# 改进asp.net mvc2中的URL,c#,asp.net-mvc,visual-studio-2010,asp.net-mvc-2,C#,Asp.net Mvc,Visual Studio 2010,Asp.net Mvc 2,改进URL 目前我在表单中有链接(显示产品信息): 我想把它整理成以下表格: 我想我需要使用路由。MapRoute,类似这样: routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"}); 这是放在默认路线之上的(因此应该覆盖我被引导相信的路线) 产品控制器如下所示: // // GET: /Products/ publ
路由。MapRoute
,类似这样:
routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"});
这是放在默认路线之上的(因此应该覆盖我被引导相信的路线)
产品控制器如下所示:
//
// GET: /Products/
public ActionResult Index([DefaultValue(1)] int page)
{
var productsToShow = //omitted for simplicity
var viewModel = new ProductIndexViewModel
{
ProductList = //omitted for simplicity,
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = productsToShow.Count()
}
};
//Passed to view as ViewData.Model (or simply Model)
return View(viewModel);
}
我做错了什么?更改
routes.MapRoute
routes.MapRoute(null, "Products/Page{page}", new {controller = "Products", action = "Index"});
正确-惯例是所有控制器类都以单词controller
结尾。因此,路由不需要您在路由详细信息中添加完整的单词,如上所述。正如@Akyegane所说,controller=“Products”。。不是“产品控制器”