title: ASP.NET MVC Conditional validation
body: <p>How to use data annotations to do a conditional validation on model?</p>
  
  <p>For example, lets say we have the following model (Person and Senior):</p>
  
  <pre><code>public class Person
  {
      [Required(ErrorMessage = "*")]
      public string Name
      {
          get;
          set;
      }
  
      public bool IsSenior
      {
          get;
          set;
      }
  
      public Senior Senior
      {
          get;
          set;
      }
  }
  
  public class Senior
  {
      [Required(ErrorMessage = "*")]//this should be conditional validation, based on the "IsSenior" value
      public string Description
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>And the following view:</p>
  
  <pre><code>&lt;%= Html.EditorFor(m =&gt; m.Name)%&gt;
  &lt;%= Html.ValidationMessageFor(m =&gt; m.Name)%&gt;
  
  &lt;%= Html.CheckBoxFor(m =&gt; m.IsSenior)%&gt;
  &lt;%= Html.ValidationMessageFor(m =&gt; m.IsSenior)%&gt;
  
  &lt;%= Html.CheckBoxFor(m =&gt; m.Senior.Description)%&gt;
  &lt;%= Html.ValidationMessageFor(m =&gt; m.Senior.Description)%&gt;
  </code></pre>
  
  <p>I would like to be the "Senior.Description" property conditional required field based on the selection of the "IsSenior" propery (true -> required). How to implement conditional validation in ASP.NET MVC 2 with data annotations?</p>