title: MVC Html Helper MultiSelect CheckBox
body: <pre><code>        public ActionResult Edit(int? id)
      {
          ViewBag.Role = new SelectList((from t in db.Roles where t.RoleID != 1 &amp;&amp; t.RoleID != 2 select t), "RoleID", "RoleName");
  
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
  
          User user = db.Users.Find(id);
  
          if (user == null)
          {
              return HttpNotFound();
          }
  
          return View(user);
      }
  </code></pre>
  
  <p>The ViewBag.Role is to generate all the Roles Value into the multiselect checkbox.</p>
  
  <pre><code>        &lt;div class="form-group"&gt;
          @Html.Label("Roles", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownList("Role", null, htmlAttributes: new { @multiple = "multiple", @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  $(function () {
      $('#Role').multiselect({
          includeSelectAllOption: true
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>Basically the MultiSelect CheckBox look like the following image.</p>
  
  <p><a href="https://i.stack.imgur.com/ihKBI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ihKBI.png" alt="enter image description here"></a></p>
  
  <p>Here is my question, how do i precheck the roles that the user already have ??
  For example, x user have a role Manager so during edit page Manager checkbox will be checked.</p>