Rebinding Nonobtrusive JavaScript Validation after AJAX postbacksAdd to My Brief

Benjamin Tinker | 12/09/2011

Recently I was faced with the wonderful prospect in MVC 3 of building a form that consisted of multiple page tabs controlled by jQuery and multiple postbacks. They had to be able to work exclusive of each other and with their own sets of validation rules. The nightmare was after post backs trying to rebind the jQuery validation for my explicit rules and those generated by the unobtrusive jQuery validator controls of MVC 3. Upon post back I was creating updated Views that contained new controls that required validation binding. So how could it be done. Easy, well not really. After trawling and trawling the web for an answer that was threatening my own sanity I came across a simple call.

$.validator.unobtrusive.parse("#form");

And that was it. jQuery validation rebinding with $.validate(‘#form’); was not enough as this did not take into account MVC using unobtrusive validation rules. So the call above was able to cover rebinding the validation of both the explicit validation rules and all my new dynamic rules added against the new controls.

Peace out.

tags: Web Development

Interested in learning more?

Wiliam is a leading supplier of web solutions and can provide expert advice to assist your business or organisation online.

Make enquiry   Request quotation

Comments

Share this page

Print this page Email this page to a friend Bookmark and Share

No Brief added yet.

My Brief results-driven approach emphasises a commitment to our clients needs through strategic analysis and best-practice.

Add to My Brief

Click on this icon to save item into My Brief. Retrieve, email and print

Drag & Drop

Drag & drop any iten with this icon into My Brief. Retrieve, email and print

Search Blogs