public async Task <ActionResult> Edit([Bind(Include = "Email,Id")] EditUserViewModel editUser, params string[] selectedRole) { if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindByIdAsync(editUser.Id); if (user == null) { return(HttpNotFound()); } user.UserName = editUser.Email; user.Email = editUser.Email; System.Collections.Generic.IList <string> userRoles = await UserManager.GetRolesAsync(user.Id); selectedRole = selectedRole ?? new string[] { }; Microsoft.AspNet.Identity.IdentityResult result = await UserManager.AddToRolesAsync(user.Id, selectedRole.Except(userRoles).ToArray <string>()); if (!result.Succeeded) { ModelState.AddModelError("", result.Errors.First()); return(View()); } result = await UserManager.RemoveFromRolesAsync(user.Id, userRoles.Except(selectedRole).ToArray <string>()); if (!result.Succeeded) { ModelState.AddModelError("", result.Errors.First()); return(View()); } return(RedirectToAction("Index")); } ModelState.AddModelError("", "Something failed."); return(View()); }