I am new to .NET trying to get a list of all the registered user along with their role names and send them to a view using a viewModel.
Here's the ViewModel:
public class ApplicationUserListViewModel
{
[Display(Name = "User Email Address")]
public string UserEmail { get; set; }
public List<IdentityUserRole<string>> Roles { get; set; }
}
I tried this for getting all users along with their roles and make a ViewModel for each user and put all the view models in a list to pass to the View:
var users = _userManager.Users.ToList();
var userList = users.Select(u =>
new ApplicationUserListViewModel {
UserEmail = u.Email,
Roles = u.Roles.ToList() }
).ToList();
But this always gives me 0 roles count for every user when I clearly have roles assigned to every user.