在 _LoggedInUser.cshtml(位于应用程序根目录的 Views/Shared 文件夹中) View 中,我想调用 AC Controller 的注销方法。我在这里有两个选择:
使用 Action 链接
@Html.ActionLink("Logout", "Logout", "AC", new { area = string.Empty })
或
<a href="@Url.Action("Logout", "AC", new { area = string.Empty })">Logout</a>
我指定区域是因为我想调用 AC Controller 的操作方法,而不管它在哪个区域。
据我了解@Html.ActionLink() 和@Url.action 之间的区别在于,首先生成一个 anchor 标记,然后第二个返回一个 url(如果我错了,请纠正我),所以我想两者都应该定位到同一位置,但此处 @Html.ActionLink 具有以下链接位置:
http://localhost:13974/Home/logout?Length=2
鉴于<a href="@Url.Action(
.... 具有以下链接位置:
http://localhost:13974/AC/Logout
当区域属性被移除时,两个链接都工作正常,但当我指定区域时,@Html.ActionLink() 中断
为什么当我指定区域时两个链接都指向不同的位置?
最佳答案
你可以使用
@Html.ActionLink("Logout", "Logout", "AC", new { area = string.Empty }, null)
您可以使用重载,LinkExtensions.ActionLink Method (HtmlHelper, String, String, String, Object, Object)
欲了解更多信息,请访问 LinkExtensions.ActionLink
此外,
LinkExtensions.ActionLink 方法(HtmlHelper、String、String、String、Object)没有重载
关于c# - 在 Asp.net MVC 4 中指定区域属性时,ActionLink 和 Url.Action 定位不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20739206/