Show Roles in users grid is always empty


if I add the "role" property as a column to the users grid it is always empty:


The role property is in this case a list of objects. Radzen cannot just display a list of something without knowing what propery to show.

Can you show me the propery Role on the User object then i can help you further

I want to show the Name of all assigned roles - it seems that the Roles collection is always empty?

Do you assign any roles?

sure - there are many entries with roles

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">
           @string.Join(", ", context.Roles.Select(r => r.Name))

The final result would look like this:

1 Like

Thanks a lot - it works :smiley: