I defined a link in my view:
@Html.ActionLink("Baxter", "Label", new { LabelName = "Baxter" })
I defined a route to catch this link like this:
routes.MapRoute(
"Search Affaire Only Label", // Route name
"{controller}/Label/{LabelName}", // URL with parameters
new { controller = "Affaire", action = "SearchAffaires", LabelName = UrlParameter.Optional } // Parameter defaults
);
The link works but the url is not correctly segmented in the address bar as you can see below:
http://localhost:3817/Affaire/Label?LabelName=Baxter
I thought the url would be formatted like this:
http://localhost:3817/Affaire/Label/Baxter
What’s wrong? Any idea?
Thanks.
In your anchor you are passing
Labelas action name (the second argument of theActionLinkhelper) whereas in your route definition you have defined theSearchAffairesaction. So either fix your anchor by also including the controller:or more explicitly give the controller name as well to avoid any ambiguity:
or modify your route definition to use the
Labelaction on theAffairecontroller.