title: MVC CheckBoxList model binding with non boolean
body: <p>I want to bind a List to CheckBox and get the selected values. I need to display two such Checkbox tables and have to retrieve both the IDs.</p>
  
  <p>Below is my ViewModel</p>
  
  <pre><code>public partial class ViewModel_Role_Security
  {
      public List&lt;Roles&gt; oRoleMaster { get; set; }
      public List&lt;Securities&gt; oSecurityMaster { get; set; }
  
  }
  </code></pre>
  
  <p>All these three have these two values
  1. ID
  2. Name (In this case for Role - ID, RoleName | for Securities - ID, SecurityName ...)
  //add 3rd property of type bool isselected in order to work eith checkboxes only then you will get it posted back
  These <strong>don't</strong> have any <strong>boolean</strong> values</p>
  
  <p>By using this ViewModel I'm binding these items using the below method...</p>
  
  <pre><code>public ActionResult AddingRoleSecurity()
  {        
      ListRoles = new List&lt;Roles&gt;();
      ListSecurities = new List&lt;Securities&gt;();  //And then populate them with data ...
  
      var model = new ViewModel_Role_Security();
      model.oRoleMaster = ListRoles;
      model.oSecurityMaster = ListSecurities;
      return View(model);
  }
  </code></pre>
  
  <p>My corresponding cshtml file is..</p>
  
  <pre><code>@model KnackWFM.BusinessEntities.ViewModel_Role_Security
  
  @using (Html.BeginForm())
  {
      &lt;div class="contentsecurity"&gt;
  
          &lt;div class="User_role"&gt;
              &lt;p class="Security_role"&gt;User Role&lt;/p&gt;
  
              @for (int i = 0; i &lt; Model.oRoleMaster.Count; i++)
              {
                  &lt;input id="@Model.oRoleMaster[i].RoleID" name="@Model.oRoleMaster[i].RoleName" type="checkbox" value="@(Model.oRoleMaster[i].RoleName)" /&gt;
                  &lt;label for="@Model.oRoleMaster[i].RoleID"&gt;@Model.oRoleMaster[i].RoleName&lt;/label&gt;
                  &lt;br /&gt;
                  @Html.CheckBoxFor(Model.oRoleMaster[i].RoleID.selec)
              }
  
          &lt;/div&gt;
  
          &lt;div class="User_Page"&gt;
              &lt;p class="Security_role"&gt;Role Security&lt;/p&gt;
  
              @for (int i = 0; i &lt; Model.oSecurityMaster.Count; i++)
              {
                  &lt;input id="@Model.oSecurityMaster[i].SecurityID" name="@Model.oSecurityMaster[i].SecurityName" type="checkbox" value="@(Model.oSecurityMaster[i].SecurityName)" /&gt;
                  &lt;label for="@Model.oSecurityMaster[i].SecurityID"&gt;@Model.oSecurityMaster[i].SecurityName&lt;/label&gt;
                  &lt;br /&gt;
              }
  
          &lt;/div&gt;
          &lt;div class="bottombuttonsecurity"&gt;
              &lt;button type="submit" id="btnSave" name="Command" value="Save" style="background-color: #3d3c4c;border-radius: 8px;color: white;padding: 5px;border: 1px solid #3d3c4c;"&gt;Save&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>For which I get the following output,
  <img src="https://i.stack.imgur.com/jQZ3d.png" alt="enter image description here"></p>
  
  <p>I would want to get the checked values as a model.</p>
  
  <p>I have a HttpPost method like this, but it returns null values.</p>
  
  <pre><code>[HttpPost]
  public ActionResult AddingRoleSecurity(ViewModel_Role_Security model)
  {
      return View();
  }
  </code></pre>
  
  <p>Please let me know how do I get the checked in values in the model?</p>
  
  <p>Thank you very much!</p>