title: Applying Data Annotations to sub properties of the View Model in MVC?
body: <p>Putting simple Data Annotations on properties is great,</p>
  
  <pre><code>public class UnicornViewModel
  {
     [Required]
     public string Name { get; set; }
  </code></pre>
  
  <p>But lets say I'm have something like this:</p>
  
  <pre><code>public class SuperPower
  {
     public class Name { get; set; }
  }
  
  public class UnicornViewModel
  {
     [Required]
     public string Name { get; set; }
  
     public SuperPower PrimarySuperPower { get; set; }
  
     public SuperPower SecondarySuperPower { get; set; }
  </code></pre>
  
  <p>How do I apply the Required attribute on PrimarySuperPower.Name while leaving it optional for SecondarySuperPower.Name? Preferably 1. something that ties into client side validation and 2. with out any special handling like checking the value of PrimarySuperPower.Name in the Action/Custom validator and add a ModelState error if it's empty. It would be great if there was something like:</p>
  
  <pre><code>   [Required(p =&gt; p.Name)]
     public SuperPower PrimarySuperPower { get; set; }
  
     public SuperPower SecondarySuperPower { get; set; }
  </code></pre>