Show Roles in users grid is always empty

Roles are empty as they are not included by default. Here is how to display them.

  1. Open SecurityService.cs and change the GetUsers method to this:
        public async Task<IEnumerable<ApplicationUser>> GetUsers()
        {
            var uri = new Uri(baseUri, $"ApplicationUsers");
    
            uri = uri.GetODataUri(expand:"Roles"); // Get the roles as well
    
            var response = await httpClient.GetAsync(uri);
    
            var result = await response.ReadAsync<ODataServiceResult<ApplicationUser>>();
    
            return result.Value;
        }
    
  2. Set the Template of the Roles data grid column to this:
    <RadzenDataGridColumn TItem="YourApp.Models.ApplicationUser" Property="Roles">
       <Template>
           @string.Join(", ", context.Roles.Select(r => r.Name))
       </Template>
    </RadzenDataGridColumn>
    

The final result would look like this:

1 Like