1

I have the following code from my account controller:

// GET: /Account/Register
        [AllowAnonymous]
        public ActionResult Register()
        {
            ViewData["roleName"] = new SelectList(Roles.GetAllRoles(), "roleName");
            return View();
        }

        //
        // POST: /Account/Register

        [HttpPost]
        [AllowAnonymous]
        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)
                {
                    Roles.AddUserToRole(model.UserName, "gamers");
                    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);

        }

and i have two roles

gamers and consoleadders

my question is, how do i go about setting thsi code so when a user selects a role it gets saved as it currently only saves one role which is gamers. I can get the roles visable but i can only select "gamers"

this is because of this line of code:

Roles.AddUserToRole(model.UserName, "gamers");

what else do i need so when a user is added they can select either roles and the role is set to there account

Thanks

0 Answers0