- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ASP.NET MVC 4 表单,其中有用于显示和隐藏一些 HTML 元素的复选框。访问表单页面时,RequestVerificationToken 值将正确创建为隐藏字段。某些 HTML 元素默认是隐藏的。
然后,在取消选中复选框(隐藏这些 HTML 元素)后,我勾选一个复选框以显示一些 HTML 元素,RequestVerificationToken 值消失。
因此,当我通过单击“创建”按钮提交表单时,出现以下错误:
The required anti-forgery form field "__RequestVerificationToken" is not present
如果我不取消选中该复选框,则 RequestVerificationToken 的值将存在并且表单将成功提交。
使用 jQuery/javascript 隐藏 HTML 元素。
为什么会发生这种情况?我该如何解决这个问题?在线研究错误仅建议添加以下属性。
我已经在 Create 操作方法中添加了属性,但没有在 GET 方法中添加:
// POST: /Document/Create
[HttpPost]
[ValidateAntiForgeryToken]
...
在创建表单页面中我还添加了:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
...
这是显示和隐藏元素的 Javascript:
$('div.section .input_control').change(function () {
var $target = $(this).closest('div').find('.showSection');
if (this.checked) {
$target.show();
} else {
if (confirm("Are you sure you want to exclude this section?") == true) {
$target.hide();
jQuery(':hidden').val('');
} else {
$(this).prop("checked", true);
}
}
});
最佳答案
使用 jQuery .not()。 http://api.jquery.com/not-selector/或http://api.jquery.com/not/
它会是这样的:
$(':hidden').not('__RequestVerificationToken').val('');
这样做,您将获得除防伪字段之外的所有隐藏字段。
关于javascript - 使用jquery隐藏html元素后RequestVerificationToken值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21125465/
我想将我的登录表单中由 Razor MVC 帮助程序生成的 RequestVerificationToken 传递给我用来管理应用程序身份验证的 AngularJS 服务 我的表格如下:
我对包含 @Html.AntiForgeryToken() 的表单执行的 ajax 帖子有问题。 当我通过 ajax 发布表单时,我得到以下查询字符串: http://myhost.local/Ass
我的 ASP.NET MVC 应用程序通过使用 ValidateAntiForgeryToken 属性并调用 Html.AntiForgeryToken 来编写具有 token 值的隐藏输入元素,并将
使用ASP.net MVC v2.0,任何方式更改名称__RequestVerificationToken cookies ?为了隐藏我们的底层技术堆栈,我想将 cookie 重命名为无法追溯到 AS
我正尝试在 this 之后授权云提供商在本地主机上,在 ConfigureServices 方法中,我的 Startup.cs 文件有 services.AddAntiforgery(options
我是一名优秀的程序员,十分优秀!