title: Model binding not working inside a partial view
body: <p>The problem I currently have is that in my partial view, the checkboxes are not being binded correctly by the MVC framework. The CaseViewModel.IsCaseSelected property will always be false regardless of whether or not the checkbox is selected. However, if I hardcode the html in the parent view instead of rendering a partial, then the CaseViewModel.IsCaseSelected property will be properly set corresponding to the checkboxes.</p>
  
  <p>My code is shown below.</p>
  
  <p>The form in my view looks something like this:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
  &lt;div&gt;
      &lt;label for="ProfileName"&gt;Profile Name:&lt;/label&gt;
      &lt;input type="text" name="ProfileName"&gt;&lt;br&gt;
  &lt;/div&gt;
  
  @Html.Partial("~/Views/Shared/_CasesSelection.cshtml", Model.Cases_Category1)
  
  &lt;div id="category2-cases"&gt;
      &lt;p&gt;category-2&lt;/p&gt;
      &lt;label for="select-all"&gt;Select all&lt;/label&gt;
      &lt;input id="select-all" type="checkbox" onclick="select_all_toggle(this)" /&gt;
      @for (int i = 0; i &lt; Model.Cases_Category2.Count; i++)
      {
          @Html.Label(Model.Cases_Category2[i].CasesNumber.ToString())
          @Html.CheckBoxFor(model =&gt; model.Cases_Category2[i].IsCaseSelected)
      }
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>My partial view looks like this:</p>
  
  <pre><code>@model List&lt;Models.CaseViewModel&gt;
  
  &lt;div id="some-case"&gt;
      &lt;p&gt;some-case&lt;/p&gt;
      &lt;label for="select-all"&gt;Select all&lt;/label&gt;
      &lt;input id="select-all" type="checkbox" onclick="select_all_toggle(this)" /&gt;
      @for (int i = 0; i &lt; Model.Count; i++)
      {
          @Html.Label(Model[i].CaseNumber.ToString())
          @Html.CheckBoxFor(model =&gt; model[i].IsCaseSelected)
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>The model it is binded to looks like this:</p>
  
  <pre><code>public class TestProfileVM
  {
      [Required]
      [RegularExpression(@"^[a-zA-Z0-9-_]+$")]
      public string ProfileName { get; set; }
  
      public List&lt;CaseViewModel&gt; Cases_Category1 { get; set; }
      public List&lt;CaseViewModel&gt; Cases_Category2 { get; set; }
  }
  </code></pre>
  
  <p>And finally, CaseViewModel looks like this:</p>
  
  <pre><code>public class CaseVM
  {
      public string CaseType { get; set; }
      public int CaseNumber { get; set; }
      public bool IsCaseSelected { get; set; }
  }
  </code></pre>
  
  <p>Additional information:</p>
  
  <p>Additionally, in my parent view, when I replace Model.Cases_Category2[i] with Model.Cases_Category2.ElementAt(i), the binding does not work correctly. What is the reason for this, and could it be related to the original problem? Thanks.</p>