MVC ActionLink omits action when action equals default route value
- by rjygraham
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?