How can I support conditional validation of model properties
- by Jeff
I currently have a form that I am building that needs to support two different versions. Each version might use a different subset of form fields. I have to do this to support two different clients, but I don't want to have entirely different controller actions for both.
So, I am trying to come up with a way to use a strongly typed model with validation attributes but have some of these attributes be conditional.
Some approaches I can think of is similar to steve sanderson's partial validation approach.
Where I would clear the model errors in a filter OnActionExecuting based on which version of the form was active.
The other approach I was thinking of would to break the model up into pieces using something like
class FormModel
{
public Form1 Form1Model {get; set;}
public Form2 FormModel {get; set;}
}
and then we would validate appropriately depending on