[英]ASP.NET Identity JavaScript Error on Logout
我有一個有趣的問題。 谷歌搜索后似乎沒有答案。
使用_LoginPartial.cshtml的稍微自定義的版本,單擊注銷時,似乎出現了附件錯誤。 還沒有看到這種行為,如果有人可以解決,希望能提供一些幫助。
_LoginPartial.cshtml
@if (Request.IsAuthenticated)
{
<ul class="nav navbar-nav navbar-right" style="margin-right: 15px;">
<li>
@Html.ActionLink("Hello " + ViewData["FullName"] + "!", "Index", "Manage", 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" style="margin-right: 15px;">
<li>@Html.ActionLink("Log In", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
為了完成這項工作,您應該更新您的表單並在其上添加BeginForm。 它看起來應該像這樣:
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", new { area = "" }, FormMethod.Post, new { id = "logoutForm" }))
{
<ul class="nav navbar-nav navbar-right" style="margin-right: 15px;">
<li>
@Html.ActionLink("Hello " + ViewData["FullName"] + "!", "Index", "Manage", 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" style="margin-right: 15px;">
<li>@Html.ActionLink("Log In", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
您所需要的只是POST到Logout操作。
您可以用純HTML重新添加空白表格:
<form action="Account/Logout" id="logoutForm"><form>
注銷鏈接不必在表單內。 如果您有一些CSS規則來弄亂<form>
標記內的超鏈接。
翻譯成Razor。 你可以做
using (Html.BeginForm("LogOff", "Account", new { area = "" }, FormMethod.Post, new { id = "logoutForm" })) ...
像建議的其他答案一樣。
或者只是在HTML中保持簡單,或者
<form action='@Url.Action("Logout","Account")' id="logoutForm"><form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.