title: ASP.NET MVC Model validation not working on ViewModel
body: <p>I have ViewModel that has inside a Model and some extra properties. There are validation on the model and on the property, but when executed, only validation on Model are checked, validation in the property is ignored.</p>
  
  <p>The Model:</p>
  
  <pre><code> [MetadataType(typeof(Customer_Validation))]
   public partial class Customer
   {
   }
  
   public class Customer_Validation
   {
       [Required(ErrorMessage="Please enter your First Name")]
       public string FirstName { get; set; }
  
       [Required(ErrorMessage = "Please enter your Last name")]
       public string LastName { get; set; }
  
       [Required(ErrorMessage = "Sorry, e-mail cannot be empty")]
       [Email(ErrorMessage="Invalid e-mail")]
       public string Email { get; set; }
   }
  </code></pre>
  
  <p>The ViewModel</p>
  
  <pre><code> public class RegisterViewModel
   {
       public Customer NewCustomer { get; private set; }
  
       [Required(ErrorMessage="Required")]
       public string Password { get; private set; }
  
       public RegisterViewModel(Customer customer, string password)
       {
           NewCustomer = customer;
           Password = password;
       }
   }
  </code></pre>
  
  <p>The Controller</p>
  
  <pre><code>public ActionResult Create()
  {
       Customer customer = new Customer();    
       RegisterViewModel model = new RegisterViewModel(customer, "");    
       return View(model);
  }
  
  [HttpPost]
  public ActionResult Create(Customer newCustomer, string password)
  {
       if (ModelState.IsValid)
       {
           try
           {
               // code to save to database, redirect to other page
           }
           catch
           {
               RegisterViewModel model = new RegisterViewModel(newCustomer, password);
               return View(model);
           }
       }
       else
       {
           RegisterViewModel model = new RegisterViewModel(newCustomer, password);
           return View(model);
       }
  }
  </code></pre>
  
  <p>The View</p>
  
  <pre><code>@using (Html.BeginForm())
   {
    &lt;table&gt;
     &lt;tr&gt;
      &lt;td&gt;First Name:&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(m =&gt; m.NewCustomer.FirstName)&lt;/td&gt;
      &lt;td&gt;@Html.ValidationMessageFor(m =&gt; m.NewCustomer.FirstName)&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;Last Name:&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(m =&gt; m.NewCustomer.LastName)&lt;/td&gt;
      &lt;td&gt;@Html.ValidationMessageFor(m =&gt; m.NewCustomer.LastName)&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;E-mail:&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(m =&gt; m.NewCustomer.Email)&lt;/td&gt;
      &lt;td&gt;@Html.ValidationMessageFor(m =&gt; m.NewCustomer.Email)&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;Password:&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(m =&gt; m.Password)&lt;/td&gt;
      &lt;td&gt;@Html.ValidationMessageFor(m =&gt; m.Password)&lt;/td&gt;
     &lt;/tr&gt;
    &lt;/table&gt;
  
    &lt;input type="submit" value="Register" /&gt;
   }
  </code></pre>
  
  <p>If I submit the form leaving Password empty it let go through. If I leave empty the Customer fields it do show the errors (except for the password field)</p>