title: Support for nested model and class validation with ASP.NET MVC 2.0
body: <p>I'm trying to validate a model containing other objects with validation rules using the System.ComponentModel.DataAnnotations attributes was hoping the default MVC implementation would suffice:</p>
  
  <pre><code>var obj = js.Deserialize(json, objectInfo.ObjectType);
  if(!TryValidateModel(obj))
  {
      // Handle failed model validation.
  }
  </code></pre>
  
  <p>The object is composed of primitive types but also contains other classes which also use DataAnnotications. Like so:</p>
  
  <pre><code>public class Entry
  {
      [Required]
      public Person Subscriber { get; set; }
  
      [Required]
      public String Company { get; set; }
  }
  
  public class Person
  {
      public String FirstName { get; set;}
  
      [Required]
      public String Surname { get; set; }
  }
  </code></pre>
  
  <p>The problem is that the ASP.NET MVC validation only goes down 1 level and only evaluates the properties of the top level class, as can be read on digitallycreated.net/Blog/54/deep-inside-asp.net-mvc-2-model-metadata-and-validation.</p>
  
  <p>Does anyone know an elegant solution to this? I've tried xVal, but they seem to use a non-recursive pattern (<a href="http://blog.stevensanderson.com/2009/01/10/xval-a-validation-framework-for-aspnet-mvc/" rel="noreferrer">http://blog.stevensanderson.com/2009/01/10/xval-a-validation-framework-for-aspnet-mvc/</a>).</p>
  
  <p>Someone must have run into this problem before right? Nesting objects in your model doesn't seem so weird if you're designing a web service.</p>