title: MVC3 List of Checkboxes for Role Management
body: <p>I am trying to manage roles in an MVC3 app.  The idea is that I have a list of users and when I click on the Edit Roles button on the row I get a modal window with a list of all possible roles with the ones the user is a member of checked.</p>
  
  <p>Then I can select the new roles and click save and send an ajax post back to the server to persist the changes.</p>
  
  <p>I have the modal popping up, but I'm not sure how to generate the checkboxes in a way that its easy to submit back to the server upon changing.  I want the simplest solution possible.</p>
  
  <p>Here is what I have for the partial view that the modal is populated with when you click Edit Roles:</p>
  
  <pre><code>public ActionResult ChooseRolePartial(string username)
      {
          var userRoles = Roles.GetRolesForUser(username);
          var list = new MultiSelectList(Roles.GetAllRoles());
          foreach (var item in list)
          {
              item.Selected = userRoles.Contains(item.Value);
          }
  
          var model = new ChooseRoleModel
          {
               Roles = list,
               Username = username
          };
  
          return PartialView("Partials/ChooseRolePartial", model);
      }
  </code></pre>
  
  <p>I was hoping there was an EditorFor for MultiSelectList and it would all be handled for me.  But that doesn't appear to be the case.  It just renders the text false for each of my roles.</p>
  
  <p><strong>Whats the best way to generate this list of checkboxs and submit whats checked along with the username back to the server?</strong></p>