问题
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
?
回答1:
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" })
来源:https://stackoverflow.com/questions/23388278/how-can-i-link-to-the-root-of-the-site-with-html-actionlink