如何确定低调验证不起作用的原因

发布于 2024-12-02 16:26:43 字数 404 浏览 2 评论 0原文

有没有办法追踪为什么不引人注目的验证不起作用?

我已禁用所有自定义验证器,仅使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝戈者 2024-12-09 16:26:43

确保您已引用以下脚本并且路径正确:

<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

并且您已在 web.config 中启用客户端验证:

<add key="ClientValidationEnabled" value="true" />

另一个重要的方面是,表单是否已作为 AJAX 调用的结果注入到 DOM 中,不引人注目的验证不会附加到其元素上,并且它将不起作用。您必须 使用 $.validator.unobtrusive.parse 方法手动附加注入 DOM 后 AJAX 成功回调。

此外,FireBug 的控制台选项卡对于显示代码中潜在的 javascript 错误可能很有用。

Make sure you have reference the following scripts and that the path is correct:

<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

and that you have enabled client side validation in your web.config:

<add key="ClientValidationEnabled" value="true" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文