Here is a picture of the error.在我對項目進行了一些更改後出現此錯誤。當你按下按鈕時,它應該去控制器記錄網站的用戶。我重新將我的佈局重新引導,並更改/刪除了屬於該網站的很多CSS。這可能是相關的,但不知道如何。這裏是按鈕的代碼:未捕獲TypeError:無法調用null的方法'submit'
@if (Request.IsAuthenticated) {
<text>
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>
}
</text>
} else {
<ul>
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>
}
有沒有人知道爲什麼會發生這種情況?
'getElementById('logoutForm')'爲空,請檢查表單是否存在 – Marthijn
使用視圖源來驗證您的註銷表單中的dos有已呈現的ID – rene
@Marthijn @rene好像logoff isent是新版本,顯然是這樣的:http://i.imgur.com/hKBdtty.png。在我的舊版本中,我也在css文件中包含這行代碼:'#logoutForm {display:inline; }'。我應該閱讀CSS還是可以讓表單不存在? – JazzMaster