Reputation: 9332
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.
Upvotes: 1
Views: 32
Reputation: 1038720
In your anchor you are passing Label
as action name (the second argument of the ActionLink
helper) whereas in your route definition you have defined the SearchAffaires
action. So either fix your anchor by also including the controller:
@Html.ActionLink("Baxter", "SearchAffaires", new { LabelName = "Baxter" })
or more explicitly give the controller name as well to avoid any ambiguity:
@Html.ActionLink("Baxter", "SearchAffaires", "Affaire", new { LabelName = "Baxter" }, null)
or modify your route definition to use the Label
action on the Affaire
controller.
Upvotes: 1