Reputation: 9342
I would like to optimize my URL showed in web browsers. I know Routing is perfect for that but I don't know if it is possible the way I want. I have a list of projects in a list. Each project have an ID, a name and a category. When navigating to the detail product page, the URL showed should be "/category/name". I know I can pass the ID, the category and the name in the ActionLink and adjusting the routing in Global.asax. I already do that but I still have the ID which is concatenate to the rest of the URL. This is ugly.
Here is an example:
The ActionLink in my view:
@Html.ActionLink(@p.Name, "Detail", new { projectID = @p.ProjectID, category = @p.Category, name = @p.Name })
the Global.asax:
routes.MapRoute(null,
"{category}/{name}",
new { controller = "Project", action = "Detail" }
);
The resulting URL:
As you can see, the projectID is always added to the end of the URL. How can I avoid that behaviour?
Thanks.
Upvotes: 2
Views: 1075
Reputation: 5124
routes.MapRoute(null,
"{category}/{name}/{projectID}",
new { controller = "Project", action = "Detail", projectID = UrlParameter.Optional }
);
will give you
/INDUSTRIE/Mailing/16
is that what you want ?
Upvotes: 2