title: Get multiple checked checkbox values in MVC controller
body: <p>My code is below:</p>
  
  <p>On page i have a products list with checkbox, code &amp; name of that product.
  When selecting multiple checkboxes, on submit click, i need to get the selected checkbox values &amp; save it in the DB.</p>
  
  <p>Product View Model class:</p>
  
  <pre><code>public class ProductVM
  {
   public ProductVM()
      {
          this.ProductsList = new List&lt;Product&gt;();
      }
  
  public List&lt;Product&gt; ProductsList { get; set; }
  
  public class Product
  {
      public bool IsSelected { get; set; }
      public string Code { get; set; }
      public string Name { get; set; }
  }
  
  }
  </code></pre>
  
  <p>Product Controller:</p>
  
  <pre><code>[HttpGet]
  public ActionResult Edit()
  {
  var model = new ProductVM();
  
          var product1 =  new ProductVM.Product
              {
                  Code = "Product1",
                  Name = "Apple"
              };
  
  
          var product2 =  new ProductVM.Product 
              {
                  Code = "Product2",
                  Name = "Banana"
              };
  
          model.ProductsList.Add(Product1);
          model.ProductsList.Add(Product2);
  
          return View(model);
       }
  
  [HttpPost]
  public ActionResult Edit(ProductVM model)
  {
  if (model.ProductsList.Any(m =&gt; m.Selected))  
          {
             //How to get the selected Code &amp; Name here
          }
  }
  </code></pre>
  
  <p>Product View:</p>
  
  <pre><code>@model ProductVM
  @using(Html.BeginForm())
  {
     foreach (var item in Model.ProductsList)
     {
          @Html.CheckBox("IsSelected", item.IsSelected) 
          @Html.Label(item.Code)
          @Html.Label(item.Name)
     }
     &lt;input type="submit" /&gt;
   }
  </code></pre>