title: Validation of a Dropdown which property comes from model but created from a RenderAction
body: <p>I have the following Address ViewModel:</p>
  
  <pre><code>public class AddressViewModel
  {
      [StringLength(20, MinimumLength = 2, ErrorMessage = "Country name is too short")]
      public String Country { get; set; }
  
      public String City { get; set; }
      public String Street { get; set; }
      public String Number { get; set; }
      public String ApartmentBuilding { get; set; }
      public String Sector { get; set; }
  }
  </code></pre>
  
  <p>And the view that renders it:</p>
  
  <pre><code>&lt;div class="control-group offset2 span6"&gt;
      @Html.LabelFor(m =&gt; m.Country)
      &lt;div class="controls"&gt;
          @{
              var countryCtrlName = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName("Country");
              Html.RenderAction("List", "Country", new { ControlName = countryCtrlName });
          }
          @Html.ValidationMessageFor(m =&gt; m.Country)
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Html.RenderAction("List") calls a controller method that gets all countries from the database and renders and renders a partial with the dropdown, here's the view:</p>
  
  <pre><code>@model IEnumerable&lt;SelectListItem&gt;
  @{var controlName = (string)ViewBag.ControlName;}
  @Html.DropDownList(controlName, Model, new {@class = ViewBag.CssClass})
  </code></pre>
  
  <p>Even though my DropdownList control is rendered with the correct name and thus mapped to the correct ViewModel upon POST, the  input control isn't decorated with the necessary data-val attributes to enable client-side validation (I believe this is because the model for the partial is IEnumerable instead of the the string property that holds the country name.  </p>
  
  <p>The address view model is used through my application as a nested property on many views. Any ideas on how to make it validate?</p>
  
  <p><strong>Edit: updated ViewModel based on @Robert's answer:</strong> </p>
  
  <p>public class AddressViewModel
  {
      [StringLength(20, MinimumLength = 2, ErrorMessage = "Country name is too short")]
      public String Country { get; set; }</p>
  
  <pre><code>public String City { get; set; }
  public String Street { get; set; }
  public String Number { get; set; }
  public String ApartmentBuilding { get; set; }
  public String Sector { get; set; }
  
  public IEnumerable&lt;CountryViewModel&gt; CountryList {get; set;}
  
  //Constructor to pass the list of countries
  public AddressViewModel(IEnumerable&lt;CountryViewModel&gt; countries)
  {
      this.CountryList = countries;
  }
  </code></pre>
  
  <p>}</p>