如何确定低调验证不起作用的原因
有没有办法追踪为什么不引人注目的验证不起作用?
我已禁用所有自定义验证器,仅使用 MVC 验证器,但当我单击“提交”时,它仍然会发回服务器进行验证。
这让我抓狂。我唯一能想到的是,我有一个隐藏输入,除了 [HiddenInput(DisplayValue = false)]
之外,没有任何验证属性。
是否有一个特定的 JavaScript 函数可以在其中放置断点来确定哪个字段导致表单提交?
编辑:
我刚刚意识到只有 IE8 才会导致服务器端验证。 IE9、FF、Chrome都可以。
编辑2:
好的,这一定是缓存问题或其他问题。在某个时候它又开始工作了,即使在恢复一切之后它仍然可以工作。
吸取教训。当遇到愚蠢的问题时,请务必清除缓存。
Is there a way to trace why unobtrusive validation is not working?
I have disabled all my custom validators, and just using MVC validators, and still it posts back to the server for validation when I click submit.
It's driving me nuts. The only thing i can think of is that i have a hidden input that has no validation attributes on it other than [HiddenInput(DisplayValue = false)]
.
Is there a specific javascript function i can put a breakpoint in to determine which field is causing the form to submit?
EDIT:
I just realize that only IE8 is causing the server side validation. IE9, FF, and Chrome all are fine.
EDIT 2:
Ok, it must have been a cache issue or something. At some point it started working again, and it's still working even after restoring everythng.
Lesson learned. Alwasy clear you cache when you get goofy problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您已引用以下脚本并且路径正确:
并且您已在 web.config 中启用客户端验证:
另一个重要的方面是,表单是否已作为 AJAX 调用的结果注入到 DOM 中,不引人注目的验证不会附加到其元素上,并且它将不起作用。您必须 使用
$.validator.unobtrusive.parse
方法手动附加注入 DOM 后 AJAX 成功回调。此外,FireBug 的控制台选项卡对于显示代码中潜在的 javascript 错误可能很有用。
Make sure you have reference the following scripts and that the path is correct:
and that you have enabled client side validation in your web.config:
Another important aspect is that if the form has been injected into the DOM as a result of an AJAX call, unobtrusive validation will not be attached to its elements and it will not work. You will have to attach it manually by using the
$.validator.unobtrusive.parse
method in your AJAX success callback after injecting it into the DOM.Also FireBug's console tab is might be useful in showing potential javascript errors with your code.