2

I have this ActionLink to login:

@Html.ActionLink("Login", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })

From the Home view, it works, resulting in this url:

http://localhost:12676/Account/Login

But then, when another area is accessed, the ActionLink results in this url:

http://localhost:12676/Admin/ManagerAccounts/Login/loginLink

What do I need to change to cause the ActionLink to always result in ~/Account/Login?

xdumaine
  • 10,096
  • 6
  • 62
  • 103
user1911
  • 680
  • 1
  • 14
  • 36

1 Answers1

10

To force the ActionLink to be relative to the root of the site, and not the current Area, give it an empty string Area as a route value, otherwise it will try to use the current area in the route:

@Html.ActionLink("Login", "Login", "Account", routeValues: new { Area = "" }, htmlAttributes: new { id = "loginLink" })
jmoreno
  • 12,752
  • 4
  • 60
  • 91
xdumaine
  • 10,096
  • 6
  • 62
  • 103
  • It works but without routeValues:, I use this: `@Html.ActionLink("Login", "Login", "Account", new { Area = "" }, htmlAttributes: new { id = "loginLink" })` – user1911 Apr 30 '14 at 13:38
  • @user1911 THat's actually the same thing, just without naming the parameters. Named parameters are optional in C#. – xdumaine Apr 30 '14 at 13:48