use*_*714 7 asp.net-mvc asp.net-mvc-areas asp.net-mvc-5 asp.net-identity
我有一个MVC5应用程序,有许多不同的领域.该项目是使用导航栏中的"注销"链接创建的,但如果用户位于任何"区域"中,则链接将断开.我想补充一下:
new { area = "" }
Run Code Online (Sandbox Code Playgroud)
将链接指向正确的位置但是它没有或我在错误的地方尝试过.代码如下:
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="nav navbar-nav navbar-right">
<li>
@Html.ActionLink("Hello " + User.Identity.GetUserName(), "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
}
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
Run Code Online (Sandbox Code Playgroud)
无论用户目前在哪个区域,有关需要更改的内容的任何想法都可以使Log Off工作?
thm*_*shd 14
正确的地方在Html.BeginForm(...)
参数范围内:
using (Html.BeginForm("LogOff", "Account", new { area = "" }, FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1943 次 |
最近记录: |