【发布时间】:2014-01-03 20:40:04
【问题描述】:
Here is a picture of the error. 这个错误是在我对我的项目进行一些更改后出现的。当您按下按钮时,它应该转到用于记录网站用户的控制器。我重新制作了我的布局以引导并更改/删除了很多属于该站点的 CSS。这可能是相关的,但不确定如何。这是按钮的代码:
@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')为空,请检查表单是否存在 -
使用查看源代码验证您的注销表单是否已呈现 id
-
@Marthijn @rene 在新版本中注销似乎是一种形式,这一点很明显:i.imgur.com/hKBdtty.png。在我的旧版本中,我在 css 文件中也有这行代码:
#logoutForm { display: inline; }。我应该阅读 CSS 还是什么可能导致表单不存在? -
新版本的
<form>缺少id属性。 -
在那个线程中,他们说表单中的 JavaScript 不起作用,我对此没有经验。您还可以将
<a href..更改为<input type="submit" />,或使用@Khalid Abuhakmeh 下面的jQuery 解决方案
标签: javascript jquery asp.net-mvc twitter-bootstrap