title: MVC 3 - Binding to a Complex Type with a List type property
body: <p>I have a following view model and it will be used by a search control that I'm working on.</p>
  
  <pre><code>public class SearchViewModel
  {
      public SearchViewModel()
      {
          SearchLocation = new SearchLocationViewModel();
          SearchCategories = new SearchCategoriesViewModel();
      }
  
     public SearchLocationViewModel SearchLocation { get; set; }
     public SearchCategoriesViewModel SearchCategories { get; set; }
  }
  </code></pre>
  
  <p>Now, SearchCategoriesViewModel has the following structure:</p>
  
  <pre><code>public class SearchCategoriesViewModel
  {
      [Display(Name = "Categories")]
      public IList&lt;SearchCategoryViewModel&gt; Categories { get; set; }
  
      public SearchCategoriesViewModel()
      {
          Categories = new List&lt;SearchCategoryViewModel&gt;();
      }
  }
  </code></pre>
  
  <p>And, finally, search category view model has the following structure:</p>
  
  <pre><code>    public class SearchCategoryViewModel
      {
          [Required]
          [Display(Name="Id")]
          public int Id { get; set; }
  
          [Display(Name="Name")]
          public String Name { get; set; }
  
          public bool IsSelected { get; set; }
      }
  </code></pre>
  
  <p>When I submit a search request, the SearchLocationViewModel comes through with submitted parameters, however, SearchCategoriesViewModel comes through empty (not null).</p>
  
  <p>Below is an editor template for my SearchCategoryViewModel:</p>
  
  <pre><code>@model MyDLL.WebUI.Models.SearchCategoriesViewModel
  
  @foreach (var c in Model.Categories)
  {
      @Html.Label(c.Name);
      @Html.CheckBox(c.Name,c.IsSelected);
  }
  </code></pre>
  
  <p>I use the following view to generate the search controls:</p>
  
  <pre><code>@using (Html.BeginForm()) {
      @Html.ValidationSummary(true) 
  
      &lt;div id="search"&gt;
          @Html.EditorFor(m =&gt; m.SearchCategories, "SearchCategory")            
          @Html.EditorFor(m =&gt; m.SearchLocation, "SearchLocation")            
      &lt;/div&gt;
  
      &lt;p&gt;
          &lt;input type="submit" value="Create" /&gt;
      &lt;/p&gt;    
  }   
  </code></pre>
  
  <p>I end up with the following markup:</p>
  
  <pre><code>   &lt;h2&gt;Search&lt;/h2&gt;
  
  &lt;form action="/Settings/Search" method="post"&gt;        
  
  
  &lt;label for="SearchCategories_Professional"&gt;Professional&lt;/label&gt;
  &lt;input id="SearchCategories_Professional" name="SearchCategories.Professional" type="checkbox" value="true" /&gt;
  &lt;input name="SearchCategories.Professional" type="hidden" value="false" /&gt;
  
  &lt;label for="SearchCategories_Associate"&gt;Associate&lt;/label&gt;&lt;input id="SearchCategories_Associate" name="SearchCategories.Associate" type="checkbox" value="true" /&gt;
  &lt;input name="SearchCategories.Associate" type="hidden" value="false" /&gt;            
  
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt; 
  
  &lt;/form&gt;
  </code></pre>
  
  <p>I suspect that the parameters are not coming through because generated markup is wrong. Did any of you try generating partial views from complex objects? I don't want to pass IEnumerable, I would rather have it encapsulated in a seperate class so that I can extend/remove it in the future if needed.</p>
  
  <p>Thank you</p>