title: Add User Roles on Registration (Forms Authentication) MVC3
body: <p>I am developing an MVC 3 project and want to add a user to a role when they are registered, using Forms Authentication. So I'd like to create some check boxes, or a drop down list showing the roles, which are selected and the user is assigned to the role as they are registered.</p>
  
  <p>I have this code so far, which works:</p>
  
  <pre><code>    public ActionResult Register()
      {
          ViewData["roleName"] = new SelectList(Roles.GetAllRoles(), "roleName");
          return View();
      }
  </code></pre>
  
  <p>And in the view I have:</p>
  
  <pre><code>&lt;label for="roleName"&gt;Select Role:&lt;/label&gt;
  @Html.DropDownList("roleName")
  @Html.ValidationMessage("roleName")
  </code></pre>
  
  <p>This is HttpPost section of the controller, and this is the part that I don't know what to code:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Register(RegisterModel model)
      {
          if (ModelState.IsValid)
          {
              // Attempt to register the user
              MembershipCreateStatus createStatus;
              Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
  
              if (createStatus == MembershipCreateStatus.Success)
              {
                  FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                  return RedirectToAction("Index", "Home");
              }
              else
              {
                  ModelState.AddModelError("", ErrorCodeToString(createStatus));
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
  </code></pre>
  
  <p>So, all the roles do show up in the view. All I need to know is what to add to the HttpPost section to get this working.</p>
  
  <p>Thanks a lot, Amy</p>