如何使用Html.ActionLink链接到网站的根目录? [英] How can I link to the root of the site with Html.ActionLink?
本文介绍了如何使用Html.ActionLink链接到网站的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个ActionLink
可以登录:
@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
但是,当访问另一个区域时,ActionLink
会导致以下URL:
But then, when another area is accessed, the ActionLink
results in this url:
http://localhost:12676/Admin/ManagerAccounts/Login/loginLink
为了使ActionLink
始终显示为~/Account/Login
,我需要更改什么?
What do I need to change to cause the ActionLink
to always result in ~/Account/Login
?
推荐答案
要强制将ActionLink相对于网站的根目录而不是相对于当前Area,请给其一个空字符串Area作为路由值,否则会尝试使用路线中的当前区域:
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" })
这篇关于如何使用Html.ActionLink链接到网站的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文