The
foreach
block in your view makes no sense - why would a class representing a single user implement
IEnumerable<???>
?
But the problem appears to be in your action:
MyUser = await _context.Users.FirstOrDefaultAsync(e => e.Id == id);
var userId = _userManager.GetUserId(User);
var user = await _context.Users.Where(u => u.Id == userId).FirstOrDefaultAsync();
await role.AddToRoleAsync(user, "admin");
That should simply be:
var user = await _context.Users.FirstOrDefaultAsync(e => e.Id == id);
await role.AddToRoleAsync(user, "admin");
await _context.SaveChangesAsync();