MVC ActionLink omits action when action equals default route value
Posted
by
rjygraham
on Stack Overflow
See other posts from Stack Overflow
or by rjygraham
Published on 2010-12-31T17:42:06Z
Indexed on
2010/12/31
17:54 UTC
Read the original article
Hit count: 437
asp.net-mvc
|actionlink
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?
© Stack Overflow or respective owner