How to Fix Mvc3 Ajax Validation Using Jquery

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'));

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source

Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.

Explore NERV on GitHub →