Bookmark and Share

How to disable and enable unobtrusive mvc 3 validators

To disable any unobtrusive validator is simple. Add the disabled attribute to the element:

$('#AddSubformButton').click(function () {

$('.nonSubformItems').attr('disabled', 'disabled');



If you only do this and you check ModelState.IsValid on the server you'll realise that the model is not valid and on reload the non-subform items will come up in red on the screen, ie. with failed validations. To disable this you physically need to remove the non-subform items from the model state sp they won't be validated.


This is also easy:

(Inside a controller post handler for instance)





//Only if subform is valid you'll get in here



Hope this helps.