title: How can I support conditional validation of model properties
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Some approaches I can think of is similar to steve sanderson's <a href="http://blog.stevensanderson.com/2010/02/19/partial-validation-in-aspnet-mvc-2/" rel="nofollow noreferrer">partial validation</a> approach.</p>
  
  <p>Where I would clear the model errors in a filter OnActionExecuting based on which version of the form was active.</p>
  
  <p>The other approach I was thinking of would to break the model up into pieces using something like</p>
  
  <pre><code>class FormModel
  {
  
  public Form1 Form1Model {get; set;}
  public Form2 FormModel {get; set;}
  }
  </code></pre>
  
  <p>and then find some way to just validate the appropriate property depending on the version.  There would also be common properties on the model that apply to both which would be always validated.</p>
  
  <p>Does anyone have a good suggestion on this?</p>