The Route:
routes.MapRoute(
"Items", // Route name
"{controller}/{action}/{id}", // URL with开发者_如何学编程 parameters
new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
The htmlhelper:
@Html.ActionLink("Chairs", "List", "Item", new {id="Chairs"}, null)
The link it generates:
http://localhost:57899/Item/List?id=Chairs
What I want it to show:
http://localhost:57899/Item/List/Chairs
How to do that?
Instead of using ActionLink what happens if you try the following?
@Html.RouteLink("Items", new { id = "Chairs" })
You call Html.RouteLink (not Action Link) and map an additional route under your generic like this:
routes.MapRoute(
"ChairsRoute", // Route name
"Item/List/{id}", // URL with parameters
new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
when you call RouteLink, you'll simply pass that "ChairsRoute" name
精彩评论