I have a ViewModel which is used for a Wizard containing two separate ViewModels which are used to load partial views into the wizard. Depending on the option selected on Step1, I need to validate either Step2 or Step3. The viewmodels for Step2 and 3 have their own AbstractValidator which works great because it includes client side validation. The problem is that if I use ModelState.IsValid, one of the VMs always fails to validate because it's empty (that step was not filled out). Is there a way to skip validation for one of the viewmodels?
The solution I eventually arrived at was surprisingly simple but I didn't spot it in the docs. You can call $('#somecontainer').valid()
which will show validation messages for supported controls and also return true
if all controls in the container are valid. It doesn't work for everything as rules like GreaterThan
aren't supported client side.