title: How to correctly submit checkbox values to controller in ASP.NET MVC
body: <p>I'm working on ASP.NET MVC web application, and I need to submit <code>List&lt;ProdColor&gt;</code> to <code>Controller</code> using <code>checkbox</code>s. Here is my code</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public partial class ProdColor
  {
      public int ProdColor_ID { get; set; }
      public Nullable&lt;int&gt; P_ID { get; set; }
      public Nullable&lt;int&gt; Color_ID { get; set; }
  
      public virtual ProdctModelView ProdctModelView { get; set; }
  }
  
  public class ProdctModelView
  {
      public ProdctModelView()
      {
          this.ProductColors = new HashSet&lt;ProdColor&gt;();
      }
  
      public int P_ID { get; set; }
      public string P_name { get; set; }
  
      public virtual ICollection&lt;ProdColor&gt; ProductColors { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult Create()
  {
      ViewBag.colorlist = db.Colors.OrderBy(m =&gt; m.Color_name).ToList();
      return View();
  }
  
  [HttpPost]
  public ActionResult Create(ProdctModelView product, List&lt;ProdColor&gt; ProductColors)
  {
      Product prod = new Product();
      //Save new product
      db.Products.Add(prod);
      db.SaveChanges();
  
      foreach (var color in ProductColors)
      {        
          color.P_ID = prod.P_ID;
          db.ProdColors.Add(color);
       }
       db.SaveChanges();
       return RedirectToAction("Index");
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@model mvc4test.Models.ProdctModelView
  @using (Html.BeginForm("Create", "CP_Product", FormMethod.Post))
  {
  
      @for (int i = 0; i &lt; ViewBag.colorlist.Count; i++)
      {                      
          &lt;input type="checkbox" id="@ViewBag.colorlist[i].Color_name" name="[@i].Color_ID" value="@ViewBag.colorlist[i].Color_id"/&gt;
      }
      &lt;input type="submit" value="Save" /&gt;
  }
  </code></pre>
  
  <p>The problem is when submitting the checkboxes without selecting the <em>first</em> one, the value of <code>List&lt;ProdColor&gt;</code> become <code>Null</code>. So how should I get the correct values at the <code>Controller</code>.</p>