如何使用Html.ActionLink链接到网站的根目录?

use*_*911 2 asp.net-mvc actionlink html.actionlink

我有这个ActionLink要登录:

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

在“主页”视图中,它可以正常工作,并产生以下网址:

http://localhost:12676/Account/Login
Run Code Online (Sandbox Code Playgroud)

但是,当访问另一个区域时,ActionLink结果将在以下URL中显示:

http://localhost:12676/Admin/ManagerAccounts/Login/loginLink
Run Code Online (Sandbox Code Playgroud)

我需要更改以导致ActionLink总是产生~/Account/Login什么?

xdu*_*ine 7

要强制ActionLink相对于站点的根目录而不是相对于当前区域,请给它一个空字符串Area作为路由值,否则它将尝试在该路由中使用当前区域:

@Html.ActionLink("Login", "Login", "Account", routeValues: new { Area = "" }, htmlAttributes: new { id = "loginLink" })
Run Code Online (Sandbox Code Playgroud)