I have the following routes defined for my application:
routes.MapRoute(
"Referral", // Route name
"{referralCode}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
And I'm trying to create an ActionLink to go on the Index action on my AdminController:
@Html.ActionLink("admin", "Index", "Admin")
However, when the view is executed the ActionLink renders as (Index action value is omitted):
<a href="/Admin">admin</a>
Normally this would be ok, but it's causing a collision with the "Referral" route.
NOTE: If I instead use ActionLink to render a different action like "Default," the ActionLink renders correctly:
<a href="/Admin/Default">admin</a>
The fact that the "Default" action renders correctly leads me to believe the problem has to do with the default value specified for the route. Is there anyway to force ActionLink to render the "Index" action as well?
Remove the default action
parameter on your Default route:
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Home"} // action omitted
);
That will force the action to always be specified in the url.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With