title: How to HTTPPost ASP.Net MVC 5 CheckBoxList to database
body: <p>I am having trouble getting the values to post to my database table from a checkboxlist.  Here are my models:</p>
  
  <pre><code>public partial class SecurityChange_Access
  {
      public int ID { get; set; }
      public string Access_Name { get; set; }
      public bool IsSelected { get; set; }
  }
  
  public partial class Change
  {
      public int ID { get; set; }
      public string Emp_FirstName { get; set; }
      public string Emp_LastName { get; set; }
      public string Emp_Supervisor { get; set; }
      public string Emp_MangerEmail { get; set; }
      public string Emp_MirrorAccount { get; set; }
      public string Security_Change_Access { get; set; }
  
      public List&lt;SecurityChange_Access&gt; SecurityAccessList { get; set; }
  
      public bool addAccess { get; set; }
      public IEnumerable&lt;SelectListItem&gt; ChangeRadioList { get; set; }
  
      //[Required(ErrorMessage = "You must select an option for TestRadio")]
      public String ChangeRadio { get; set; }
  }
  
  public class bTest
  {
      public int ID { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Here is the HTTPGet and HTTPPost:</p>
  
  <pre><code>[HttpGet]
  public ActionResult Change(Change change)
  {   
      List&lt;bTest&gt; list = new List&lt;bTest&gt;();
      list.Add(new bTest() { ID = 1, Name = "Add Access" });
      list.Add(new bTest() { ID = 2, Name = "Remove Access" });
      list.Add(new bTest() { ID = 3, Name = "Change Access" });
      SelectList sl = new SelectList(list, "Name", "Name");
      change.ChangeRadioList = sl;
  
      List&lt;ActiveDirectory&gt; objadlist = (from data in       objentity.ActiveDirectories select data).ToList();
      ActiveDirectory objAD = new ActiveDirectory();
      objAD.displayName = "";
      objAD.mail = "";
      objAD.Id = 0;
      objadlist.Insert(0, objAD);
      SelectList objmodeldata = new SelectList(objadlist, "displayName", "displayName", 0);
      /*Assign value to model*/
      change.ADList = objmodeldata;
  
      change.SecurityAccessList = new List&lt;SecurityChange_Access&gt;();
      change.SecurityAccessList = BindSecurity();
  
      return View(change);
  }
  
  public List&lt;SecurityChange_Access&gt; BindSecurity()
  {
      List&lt;SecurityChange_Access&gt; _objsecurity = (from data in _entities.SecurityChange_Access select data).ToList();
      return _objsecurity;
  }
  
  [HttpPost]
  public ActionResult Change([Bind(Include = "ID, Emp_FirstName, Emp_LastName, Emp_Supervisor, Emp_MangerEmail, Emp_MirrorAccount, Security_Change_Access, Security_Access_To_1, Security_Access_To_2, Security_Access_To_3, Security_Access_To_4, Security_Access_To_5, Security_Access_To_6, Security_Access_To_7, Security_Access_To_8, Security_Access_To_9, Security_Access_To_10, Security_Access_To_Other, Security_Access_ADF_Mirror, Security_Access_JDE_Mirror, Security_Access_NetworkDrives_1, Security_Access_NetworkDrives_2, Security_Access_NetworkDrives_3, Security_Access_NetworkDrives_4, Security_Access_NetworkDrives_5, Security_Access_NetworkDrives_6, Security_Access_NetworkDrives_7, Security_Access_NetworkDrives_8, Security_Access_NetworkDrives_9, Security_Access_NetworkDrives_10, Security_Access_NetworkDrives_11, Security_Access_NetworkDrives_12, Security_Access_NetworkDrives_13, Security_Access_NetworkDrives_14, Security_Access_NetworkDrives_15, Security_Access_NetworkDrives_16, Security_Access_NetworkDrives_17, Security_Access_NetworkDrives_18, Security_Access_NetworkDrives_19, Security_Access_NetworkDrives_20, Security_Access_NetworkDrives_21, Security_Access_NetworkDrives_22, Security_Access_NetworkDrives_23, Security_Access_NetworkDrives_24, Security_Access_NetworkDrives_25, Security_Access_NetworkDrives_26, Security_Access_NetworkDrives_27, Security_Access_NetworkDrives_28, Security_Access_NetworkDrives_29, Security_Access_NetworkDrives_30, IT_Equipment_1, IT_Equipment_2, IT_Equipment_3, IT_Equipment_4, IT_Equipment_5, IT_Equipment_6, IT_Equipment_7, IT_Equipment_8, IT_Equipment_9, IT_Software_1, IT_Software_2, IT_Software_3, IT_Software_4, IT_Software_Other, IT_Media_1, IT_Media_2, IT_Media_3, IT_Media_Other, IT_Other_Equipment, Additional_Information")] Change change, int? id)
  {
      try
      {
          if (ModelState.IsValid)
          {
              StringBuilder sb = new StringBuilder();
              sb.Append("SELECTED COUNTRY :- ").AppendLine();
              foreach (var item in change.SecurityAccessList)
              {
                  if (item.IsSelected == true)
                  {
                      sb.Append(item.Access_Name + ", ").AppendLine();
                      _entities.Changes.Add(change);
                      _entities.SaveChanges();
  
                      return RedirectToAction("Change");
                  }
              }
  
          }
  
      }
      catch (System.Data.Entity.Validation.DbEntityValidationException ex)
      {
           foreach (var e in ex.EntityValidationErrors)
          {
              //check the ErrorMessage property
          }
      }
      return View(change);
  }
  </code></pre>
  
  <p>Here is the Razor code:</p>
  
  <pre><code>&lt;table border="0" width="1000" cellpadding="5" cellspacing="5"&gt;
      @for (int i = 0; i &lt; Model.SecurityAccessList.Count; i++)
      {
          &lt;tr&gt;
              &lt;td width="200"&gt;
                  @Html.CheckBoxFor(m =&gt; Model.SecurityAccessList[i].IsSelected)
                  @Model.SecurityAccessList[i].Access_Name
                  @Html.HiddenFor(m =&gt; Model.SecurityAccessList[i].ID)
                  @Html.HiddenFor(m =&gt; Model.SecurityAccessList[i].Access_Name)
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  </code></pre>
  
  <p>In my HTTPGET I am binding my list but then I need to post my list on the checked values.  I am not sure how to go about doing this.  I am also having problems getting the checked list so it is comma separated.  I can't seem to find anything online that can help me with this.  I just can't seem to be able to post the data to the Security_Change_Access field.</p>