title: Passing model with list of checkboxes from view to controller
body: <p>I am trying to pass model from View back to controller. I am passing <code>NaborViewModel</code> to View. It is a list of objects and every object has 4 checkboxes (some of them randomly checked).</p>
  
  <p>Model:</p>
  
  <pre><code>public class NaborViewModel
  {
      public List&lt;WowClass&gt; WowClasses { get; set; }
  }
  </code></pre>
  
  <p>Actions:</p>
  
  <pre><code>    [HttpGet]
      public ActionResult Nabor()
      {
          NaborViewModel viewModel = new NaborViewModel();
          DatabaseDataContext context = new DatabaseDataContext();
          viewModel.WowClasses = context.WowClasses.ToList();
  
          return View(viewModel);
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Nabor(NaborViewModel model)
      {
          //DB actions
          return RedirectToAction(Consts.ActionNabor);
      }
  </code></pre>
  
  <p>In view i have 2 forms each with different approach. The first one is the one i have created with thought it might work. 
  The second form is approach i found online.
  The first one is displaying passed data correctly (filled checkboxes). The second one is even displaying every checboxes unchecked. 
  When forms are submitted, they both returns null back to controller action.</p>
  
  <p>View:</p>
  
  <pre><code>        @using (Html.BeginForm(Consts.ActionNabor, Consts.ControllerAdmin, FormMethod.Post))
          {
              @Html.AntiForgeryToken()
              &lt;table class="admin-table"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th&gt;Class&lt;/th&gt;
                          &lt;th&gt;Status&lt;/th&gt;
                          &lt;th colspan="3"&gt;Požadované talenty&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      @foreach (var cls in Model.WowClasses)
                      {
                          &lt;tr&gt;
                              @Html.HiddenFor(x =&gt; cls.Id)
                              &lt;td&gt;@cls.ClassName&lt;/td&gt;
                              &lt;td&gt;@Html.CheckBoxFor(x =&gt; cls.Open)&lt;/td&gt;
                              &lt;td style="text-align: left"&gt;@Html.CheckBoxFor(x =&gt; cls.NeedTalents1) &lt;span&gt;@cls.Talents1&lt;/span&gt;&lt;/td&gt;
                              &lt;td style="text-align: left"&gt;@Html.CheckBoxFor(x =&gt; cls.NeedTalents2) &lt;span&gt;@cls.Talents2&lt;/span&gt;&lt;/td&gt;
                              &lt;td style="text-align: left"&gt;@Html.CheckBoxFor(x =&gt; cls.NeedTalents3) &lt;span&gt;@cls.Talents3&lt;/span&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      }
                  &lt;/tbody&gt;
              &lt;/table&gt;
  
              &lt;input type="submit" value="@Consts.Submit" /&gt;
          }
  
          &lt;div class="horizontal-line-both"&gt;&lt;/div&gt;
  
          @using (Html.BeginForm(Consts.ActionNabor, Consts.ControllerAdmin, FormMethod.Post))
          {
              @Html.AntiForgeryToken()
              &lt;table class="admin-table"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th&gt;Class&lt;/th&gt;
                          &lt;th&gt;Status&lt;/th&gt;
                          &lt;th colspan="3"&gt;Požadované talenty&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      @for (int i = 0; i &lt; Model.WowClasses.Count; i++)
                      {
                          &lt;tr&gt;
                              &lt;td&gt;
                                  &lt;input type="text" value="@Model.WowClasses[i].ClassName" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="checkbox" value="@Model.WowClasses[i].Open" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="checkbox" value="@Model.WowClasses[i].NeedTalents1" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="checkbox" value="@Model.WowClasses[i].NeedTalents2" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="checkbox" value="@Model.WowClasses[i].NeedTalents3" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;input type="hidden" value="@i" name="Expense[@i].Id"&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      }
                  &lt;/tbody&gt;
              &lt;/table&gt;
  
              &lt;input type="submit" value="@Consts.Submit" /&gt;
          }
  </code></pre>