Thursday, July 4, 2013

MVC 3 Razor. Partial View validation is not working

Everytime you perform an AJAX call and substitute some part of your DOM with partial HTML contents returned by the controller action you need to reparse the client side unobtrusive validation rules. So in your AJAX success callbacks when after you call the .html() method to refresh the DOM you need to parse:
 function reparseForm(form) {  
       var $form = $(form);  
       $form.removeData('validator');  
       $form.removeData('unobtrusiveValidation');  
       $.validator.unobtrusive.parse(form);  
     }  

No comments: