【发布时间】:2014-01-11 09:59:18
【问题描述】:
在 _LoggedInUser.cshtml(位于应用程序根目录的 Views/Shared 文件夹中)视图中,我想调用 AC 控制器的 Logout 方法。我在这里有两个选择:
使用 ActionLink
@Html.ActionLink("Logout", "Logout", "AC", new { area = string.Empty })
或
<a href="@Url.Action("Logout", "AC", new { area = string.Empty })">Logout</a>
我指定区域是因为我想调用 AC 控制器的操作方法,而不管它在哪个区域。
据我了解@Html.ActionLink() 和@Url.action 之间的区别在于,首先生成一个锚标记,然后第二个返回一个url(如果我错了请纠正我),所以我想两者都应该定位到同一位置,但此处@Html.ActionLink 具有以下链接位置:
http://localhost:13974/Home/logout?Length=2
而<a href="@Url.Action(.... 有以下链接位置:
http://localhost:13974/AC/Logout
删除 area 属性后两个链接都可以正常工作,但当我指定区域时 @Html.ActionLink() 会中断
当我指定区域时,为什么两个链接都指向不同的位置?
【问题讨论】:
标签: c# asp.net asp.net-mvc