Improving urls
Currently I have links in the form (displaying product information):
http://localhost:XXXX/Products/?page=1
I want to clean this up into the form:
http://localhost:XXXX/Products/Page1
I think I need to do this with routes.MapRoute
, something like so:
routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"});
This was put above the default route (so should override I am led to believe)
The product controller looks like this:
//
// 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);
}
What am I doing wrong?
更改routes.MapRoute
routes.MapRoute(null, "Products/Page{page}", new {controller = "Products", action = "Index"});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.