Why doesn't Default route work using Html.ActionLink in this case?
Posted
by
StuperUser
on Stack Overflow
See other posts from Stack Overflow
or by StuperUser
Published on 2011-01-06T16:26:42Z
Indexed on
2011/01/06
17:53 UTC
Read the original article
Hit count: 283
I have a rather perculiar issue with routing.
Coming back to routing after not having to worry about configuration for it for a year, I am using the default route and ignore route for resources:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
// Route name
"{controller}/{action}/{id}",
// URL with parameters
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
I have a RulesController
with an action for Index
and Lorem
and a Index.aspx
, Lorem.aspx
in Views > Rules directory.
I have an ActionLink aimed at Rules/Index on the maseter page:
<li><div><%: Html.ActionLink("linkText", "Index", "Rules")%></div></li>
The link is being rendered as http://localhost:12345/Rules/
and am getting a 404.
When I type Index
into the URL the application routes it to the action.
When I change the default route action from "Index"
to "Lorem"
, the action link is being rendered as http://localhost:12345/Rules/Index
adding the Index
as it's no longer on the default route and the application routes to the Index action correctly.
I have used Phil Haack's Routing Debugger, but entering the url http://localhost:12345/Rules/
is causing a 404 using that too.
I think I've covered all of the rookie mistakes, relevant SO questions and basic RTFMs.
I'm assuming that "Rules" isn't any sort of reserved word in routing. Other than updating the Routes and debuugging them, what can I look at?
© Stack Overflow or respective owner