动态表单和 AntiForgeryToken MVC
我想在 MVC 页面上创建动态表单,该表单将生成类似这样的内容。
onclick="
var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', '6I6td2wJRI9Nu5Au/F3EfOQhxJbEMXabuVXM0nXonkY=');
f.appendChild(s);
f.submit();
return false;"
我只是不确定如何在上面的内容上实现 AntiForgeryToken?!? 任何帮助将不胜感激
I want to create dynamic forms on a MVC page that will generate something like this.
onclick="
var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', '6I6td2wJRI9Nu5Au/F3EfOQhxJbEMXabuVXM0nXonkY=');
f.appendChild(s);
f.submit();
return false;"
I am just not sure how I can implement the AntiForgeryToken on something like above?!?
any helpwould be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您调用的动态表单实际上是将锚链接转换为表单,以便您可以POST而不是GET。在这种情况下,我建议您直接在服务器上生成表单,而不是费心发出链接,稍后您将在
onclick
事件中使用所有这些 javascript 将其转换为表单:因此,而不是:
你可以直接:
It seems that you are calling dynamic forms is in fact an effort to convert anchor links into forms so that you can POST instead of GET. In this case I would recommend you to generate the form directly on the server instead of bothering with emitting a link which you would later turn into a form using all this javascript in the
onclick
event:So instead of:
you could directly: