Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

MVC3 ajax validation doesn't work on a jquery served form

To make automatic validation using data annotation on a model on mvc3 c# we need:
1.) A model with data annotation (ex. required attribute).
2.) Form with jquery declaration (jquery1.7, validate, validate unobtrusive, and unobtrusive-ajax. All are available under Scripts directory on an MVC template project. Note that you can update your jquery library using NuGet.
3.) App.config with <add key="ClientValidationEnabled" value="true"/> defined.

Normally, with this requirement validation should work fine. But if the form is served via ajax call, you need to rebind the form to the validator elements  using the ff code:
//your_div is the id of your element which contains the form
$.validator.unobtrusive.parse($('#your_div'));
MVC3 ajax validation doesn't work on a jquery served form MVC3 ajax validation doesn't work on a jquery served form Reviewed by Edward Legaspi on Wednesday, April 04, 2012 Rating: 5

No comments:

Powered by Blogger.