Hello everyone, I'm finding it difficult to update the user role when updating my data, my roles are being filled through a ViewBag in my get from my controller and I'm retrieving the new ID in the post from my controller through the request. form follows the code of my post.
[AllowAnonymous]
[HttpPost]
public ActionResult UserEdit(ApplicationUser appuser)
{
var context = new Models.ApplicationDbContext();
var user = context.Users.Where(u => u.Id == appuser.Id).FirstOrDefault();
user.LockoutEnabled = appuser.LockoutEnabled;
//Recupera o ID do novo item
var newRole = Request.Form["RoleId"].ToString();
//Aqui eu deveria a atualização da role
context.SaveChanges();
return RedirectToAction("UserList");
}
Thank you all.