Instead of trying to access membership tables directly from db (datacontext), you should use the static User , Roles and Membership classes provided in your action code.
Like this:
System.Web.Security.Roles.AddUserToRole(usernameID, choosenRole);
Assuming your usernameID is the string key of the user you want to change, and choosenRole contains the key of the role name that you want to add to the user:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult EditRole(string usernameID, FormCollection formValues) { string choosenRole = Request.Form["Roles"]; System.Web.Security.Roles.AddUserToRole(usernameID, choosenRole); return RedirectToAction("Index"); }
Matt kocaj
source share