title: ASP.NET MVC3 Validation of nested view model object fields
body: <p>I have a view model that looks like this:</p>
  
  <pre><code>public class VenueIndexViewModel : BaseViewModel
  {
      public VenueAddViewModel Venue;
      ...
  }
  
  public class VenueAddViewModel
  {
      ...
      [Required(ErrorMessage = "This field is required")]
      public string State { get; set; }
      ...
  }
  </code></pre>
  
  <p>In my view, I'm rendering a form with with a drop down list for this property like so:</p>
  
  <pre><code>using (var form = Html.BeginForm())
  { 
      ...
      @Html.DropDownListFor(x =&gt; x.Venue.State, Model.GetStates())
      @Html.ValidationMessageFor(x =&gt; x.Venue.State)
      ...
  }
  </code></pre>
  
  <p>This works, but the problem is that the the Required attribute on the view model appears to be ignored. If I look at the HTML, the data-val-* attributes are missing as well.</p>
  
  <pre><code>&lt;select id="Venue_State" name="Venue.State"&gt;...&lt;/select&gt;
  </code></pre>
  
  <p>However, if I change the rendering to a textbox...</p>
  
  <pre><code>using (var form = Html.BeginForm())
  { 
      ...
      @Html.TextBoxFor(x =&gt; x.Venue.State)
      @Html.ValidationMessageFor(x =&gt; x.Venue.State)
      ...
  }
  </code></pre>
  
  <p>I see the expected data-val-* attributes and the validation works:</p>
  
  <pre><code>&lt;input data-val="true" 
      data-val-required="This field is required" 
      id="Venue_State" name="Venue.State" type="text" value=""&gt;
  </code></pre>
  
  <p>I should note that I have other view models elsewhere that use DropDownListFor with a flat view model (no nested objects) and the validation works fine there, so I'm thinking I've hit a bug in the MVC validation handling for drop down lists when using a nested view model.  Can anyone confirm / advise?</p>