ASP MVC unobtrusive validation for dynamic html

When I add the dynamic content to page with javascript or ajax, the validation doesn't work with new content at all. I solved the problem by 2 ways.

Solution 1: Parse only changed content
$("#yourID").html(yourContent); // add html to your tag
$.validator.unobtrusive.parse($("#yourID")); // this will parse validation for new content
Solution 2: Parse validation for form tag
$.removeData($('#YourFormID').get(0), 'validator'); // clear the validation of the form tag
jQuery.validator.unobtrusive.parse('#YourFormID');

Posted in . Bookmark the permalink. RSS feed for this post.

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.