ASP.NET MVC 4默认_LoginPartial模板退出不工作 [英] ASP.NET MVC 4 Default _LoginPartial template Logout not working
问题描述
我已经与_layout和MVC默认的_PartialLayouts 4个模板,突然退出中的_PartialLogin文档功能已stopeed工作摆弄周围。为了给你更多的信息,该_LoginPartial.cshtml从后者又是从_Layout.cshtml
I have been fiddling around with the _Layout and _PartialLayouts of the default MVC 4 templates and suddenly the 'Logout' feature in the '_PartialLogin' doc has stopeed working. To give you more info, the _LoginPartial.cshtml is called from the _NavBar.cshtml which in turn is called from the _Layout.cshtml
在_LoginPartial.cshtml的code是:
The code of the _LoginPartial.cshtml is:
@if (Request.IsAuthenticated) {
<text>
<p>Hello, @Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "Manage" })!
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
}</p>
</text>
}
从_NavBar.cshtml的code是:
The code from the _NavBar.cshtml is:
<form class ="navbar-form navbar-right" method="post" action="/account/login">
<div class ="form-group">
@Html.Partial("_LoginPartial")
</div>
</form>
从_Layout.cshtml的code是:
The code from the _Layout.cshtml is:
<body>
@Html.Partial("_Navbar")
@RenderSection("featured", required: false)
@RenderBody()
<div class="container">
我得到的,也许问题出在JavaScript已被禁用无意中不知何故。我缺少一些脚本标签可能?又或者是在previous类,我叫从_PartialLogin ??
I get that maybe the problem is the javascript has been disabled unintentionally somehow. Am I missing some script tags maybe? Or is it something in the previous class where I called the _PartialLogin from??
推荐答案
我不回答你的问题(的您已经解决了这个问题的),但我认为这极大地提高了code:
I'm not answering your question ( you already solved the problem ) but I think this greatly improves the code:
改变这一行:
<a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
这一个:
<button class="btn btn-link">Log off</button>
也并不需要这种改变形式的ID。
also the id on the form is not needed with this change.
这篇关于ASP.NET MVC 4默认_LoginPartial模板退出不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!