0
目前,我有形式的链接(显示产品信息):
http://localhost:XXXX/Products/?page=1
我要清理这个成以下形式:
http://localhost:XXXX/Products/Page1
我想我需要做到这一点routes.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);
}
什么时我做错了?
正确 - 在*公约*的是,所有控制器类字'Controller'结束。因此,路线并不需要您将完整的单词添加到路线详情中,如上所述。所以就像@Akyegane所说的,controller =“Products”..而不是“ProductsController” – 2010-08-30 04:59:36