I have the standard ‘RequiredIf’ attribute for some Conditional-Validation.
My form and Model are fairly large, the model has 63 properties and most of which are validated.
Anyway, I have an issue where my Model is getting loaded in while my validation is executing.
If i put a breakpoint on the first line of code inside the ‘RequiredIf’ ‘IsValid’ method, I can see that my Model has a lot of null values. When I press F5 (to continue onto the validation of the next property), there are still lots of nulls. If i press F5 about 5 more times the model magically fills with the data I posted.
My first 5-6 validations are getting screwed up because of this. Anyone know anything about how the models are being loaded? I am not using custom model binding.
The solution was the completely ‘override’ the standard model binding. Create you own model binder, load in the whole model manually, then afterwards execute all of your model validation. I’m still convinced that there is some way to just say “Hey, load in the whole model before validating” in this standard Model Binder, but I had to make my own for now.