How to get the Controller Reference Syntax to work?

Jun 3, 2013 at 5:55 PM
Edited Jun 3, 2013 at 5:57 PM
I have an issue with the Controller Reference Syntax and how to get it to work at all.

My routes.axd looks like this:
routes.MapRoute(null, "{action}", 
    new { controller = @"Home", action = @"Index" }, 
    new { action = @"Index" }, 
    new[] { "mvcApp.Controllers" });

routes.MapRoute(null, "Sites/Site1/Home/{action}", 
    new { controller = @"Home", action = @"Index" }, 
    new { action = @"Index|Other" }, 
    new[] { "mvcApp.Controllers.Sites.Site1" });

routes.MapRoute(null, "Sites/Site1/Profile/{action}", 
    new { controller = @"Profile", action = @"Index" }, 
    new { action = @"Index" }, 
    new[] { "mvcApp.Controllers.Sites.Site1" });
Now if I go to (using IIS) http://site1.localhost/home I get to the correct controller and all is fine. However if I have lets say a menu on my _Layout.cshtml looking like this:
<ul id="menu">
      <li>@Html.ActionLink("Home", "Index", "Home")</li>
      <li>@Html.ActionLink("Profile", "Index", "Profile")</li>
</ul>
the Home link routes to http://site1.localhost/Sites/Site1/Home which is the correct url. However http://site1.localhost/Home links to same place and that's what I want the ActionLink to route to. But I cannot get the syntax to work at all with for instance
<li>@Html.ActionLink("Home", "Index", "..Home")</li>
How would I get the link to route to http://site1.localhost/Home instead of http://site1.localhost/Sites/Site1/Home using the Controller reference syntax?
Coordinator
Jun 3, 2013 at 7:06 PM
I'm not sure I understand what you are trying to say. I'm curious why /Home works, because it shouldn't match any of the routes you pasted above.

From layout pages you'd need to use the following syntax so the link is always generated correctly:
<li>@Html.ActionLink("Home", "Index", "~Home")</li>
If the above doesn't help please provide clarification.