开发者

How to determine why unobtrusive validation is not working

开发者 https://www.devze.com 2023-04-02 01:22 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消