title: Selected Checkboxes are not showing up in the HttpPost action method in asp.net core mvc 3.1
body: <p>I'm trying to print all the selected checkboxes in the <code>[HttpPost]</code> action method. But, I'm always getting  count as 0. Can someone suggest me where I'm doing wrong?</p>
  <p>Below is my <code>Category</code> model class.</p>
  <pre><code>public class Category
  {
      public int CategoryId { get; set; }
      public string CategoryName { get; set; }
      public bool CheckboxAnswer { get; set; }
  }
  </code></pre>
  <p>Since this is sample program, I've used <code>CategoryData</code> class like below to bind to checkbox list controls.</p>
  <pre><code>public class CategoryData
  {
      public CategoryData()
      {
      }
  
      public List&lt;Category&gt; Categories
      {
          get
          {
              var categories = new List&lt;Category&gt;
              {
                  new Category { CategoryId = 1, CategoryName = &quot;Beverages&quot;, CheckboxAnswer = true },
                  new Category { CategoryId = 2, CategoryName = &quot;Condiments&quot;, CheckboxAnswer = false },
                  new Category { CategoryId = 3, CategoryName = &quot;Confections&quot;, CheckboxAnswer = true },
                  new Category { CategoryId = 4, CategoryName = &quot;Dairy Products&quot;, CheckboxAnswer = false }
              };
              return categories;
          }
      }
  }
  </code></pre>
  <p>Below is the View: <code>GetSelectedCheckBoxes.cshtml</code></p>
  <pre><code>@model IEnumerable&lt;Practice.MVC.Models.Category&gt;
  @{
      ViewBag.Title = &quot;Get Selected CheckBoxes&quot;;
  }
  &lt;h1&gt;@ViewBag.Title&lt;/h1&gt;
  &lt;form asp-controller=&quot;Test&quot; asp-action=&quot;GetSelectedCheckBoxes&quot; method=&quot;post&quot;&gt;
      @foreach (var category in Model)
      {
          &lt;input type=&quot;checkbox&quot; asp-for=&quot;@category.CheckboxAnswer&quot; /&gt;
          &lt;label asp-for=&quot;@category.CategoryId&quot;&gt;@category.CategoryName&lt;/label&gt;
          &lt;input type=&quot;hidden&quot; asp-for=&quot;@category.CategoryId&quot; /&gt;
          &lt;input type=&quot;hidden&quot; asp-for=&quot;@category.CategoryName&quot; /&gt;
      }
      &lt;input type=&quot;submit&quot; id=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; /&gt;
  &lt;/form&gt;
  </code></pre>
  <p>Below is the <code>[HttpGet]</code> version of my <code>Controller</code> action method.</p>
  <pre><code>    public IActionResult GetSelectedCheckBoxes()
      {
          var categories = new CategoryData().Categories;
          return View(categories);
      }
  </code></pre>
  <p>Below is the <code>[HttpPost]</code> version of my <code>Controller</code> action method.</p>
  <pre><code>    [HttpPost]
      public IActionResult GetSelectedCheckBoxes(List&lt;Category&gt; categories)
      {
          string selectedCheckboxes = string.Empty;
          string notSelectedCheckboxes = string.Empty;
          foreach (var category in categories)
          {
              if (category.CheckboxAnswer)
                  selectedCheckboxes += category.CategoryName + &quot;, &quot;;
              if (!category.CheckboxAnswer)
                  notSelectedCheckboxes += category.CategoryName + &quot;, &quot;;
          }
          return Content(selectedCheckboxes + &quot; ------ &quot; + notSelectedCheckboxes);
      }
  </code></pre>
  <p>As you can see in the below screenshot, I'm not getting <code>categories</code> as parameter
  <a href="https://i.stack.imgur.com/rIMnw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rIMnw.png" alt="enter image description here" /></a></p>