Friday, 13 January 2012

Dynamically add required attribute for MVC3 jQuery unobtrusive

 

While you can add the data-val attributes for MVC client side validation by default MVC unobtrusive validation won’t process them.

What you have to do is remove the validators and re-add them.

   1:  $("#Password").attr("data-val-required", "Password is required");
   2:  $("form").removeData("validator");
   3:  $("form").removeData("unobtrusiveValidation");
   4:  $.validator.unobtrusive.parse("form");

No comments:

Post a Comment