How can I link to the root of the site with Html.ActionLink?

被刻印的时光 ゝ 提交于 2019-12-22 13:54:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!