I can get all users like this
var users = UserManager.Users.ToList();
I can find a role like this
var role = db.Roles.SingleOrDefault(m => m.Name == "User");
I want to list all users with the role name "User" in the AspNetRoles table (I have User
and Admin
).
var role = db.Roles.SingleOrDefault(m => m.Name == "User");
var usersInRole = db.Users.Where(m => m.Roles.Any(r => r.RoleId == role.Id)).ToList();
return View(usersInRole);
I get the role in var role
but userInRole
gives me Count = 0
when I debug. No compile errors.