我正在开发一个MVC项目,它有两个Areas
,在区域1中,注销按钮工作正常,但不适用于区域2
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
<ul class="lgoff">
<li class="helo" style="margin-right:190px; margin-top:30px;">
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Welcome", style = "color:#ebc424;text-decoration: none; " })
</li>
<li class="lgot" style="text-decoration: none; margin-top:5px; ">
<a href="javascript:document.getElementById('logoutForm').submit()" style="text-decoration: none;">
<img type="image" id="myimage1" src="~/img/log_out.png" style="float:right; margin-top:-35px; " />
</a>
</li>
</ul>
}
}
控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
AuthenticationManager.SignOut();
return RedirectToAction("Login", "Account");
}
答案 0 :(得分:4)
如果我理解您在主区域中的注销操作方法,但是您在Masters
区域内调用它,那么您需要告诉MVC您的操作方法在哪里:
using (Html.BeginForm("LogOff", "Account",new {area=""} , FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
}