Answers for "User List get Role Name mvc 5"

0

User List get Role Name mvc 5

var usersWithRoles = (from user in context.Users  
                                  select new  
                                  {  
                                      UserId = user.Id,                                        
                                      Username = user.UserName,  
                                      Email = user.Email,  
                                      RoleNames = (from userRole in user.Roles  
                                                   join role in context.Roles on userRole.RoleId   
                                                   equals role.Id  
                                                   select role.Name).ToList()  
                                  }).ToList().Select(p => new Users_in_Role_ViewModel()  
   
                                  {  
                                      UserId = p.UserId,  
                                      Username = p.Username,  
                                      Email = p.Email,  
                                      Role = string.Join(",", p.RoleNames)  
                                  });  
   
   
            return View(usersWithRoles);
Posted by: Guest on March-25-2020

Code answers related to "User List get Role Name mvc 5"

Browse Popular Code Answers by Language