Я использую Radzen Data Grid для отображения пользователей из таблицы AspNetUsers, но данные не отображаются.
Это мой код ниже:
@page "/contacts"
@rendermode InteractiveServer
@using BlazorApp1.Data
@using BlazorApp1.Models
@using Microsoft.EntityFrameworkCore
@inject ApplicationDbContext DbContext
<h3>Contact</h3>
<RadzenDataGrid AllowFiltering = "true" PageSize = "5" Data = "@employees" SelectionMode = "DataGridSelectionMode.Single" @bind-Value = "@selectedEmployees">
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.Id)" Filterable = "false" Title = "ID" Frozen = "true" TextAlign = "TextAlign.Center" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.Name)" Filterable = "true" Title = "Name" Frozen = "true" TextAlign = "TextAlign.Left" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.OrgUnitId)" Filterable = "true" Title = "Org/Unit" Frozen = "true" TextAlign = "TextAlign.Left" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.PhoneNumber)" Filterable = "true" Title = "Phone Number" Frozen = "true" TextAlign = "TextAlign.Left" />
</RadzenDataGrid>
@code {
IEnumerable<ApplicationUser> employees;
IList<ApplicationUser> selectedEmployees = new List<ApplicationUser>();
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
employees = await DbContext.Users.ToListAsync();
selectedEmployees = new List<ApplicationUser>() { employees.FirstOrDefault() };
}
}
Я использую серверный режим рендеринга и SQL-сервер для базы данных. Что-то не так с тем, как я это реализую?
Согласно официальной демонстрации (нажмите «Редактировать исходный код»), вам не хватает переноса элементов <RadzenDataGridColumn>
в <Columns>
.
Ваша структура <RadzenDataGrid>
должна быть такой, как показано ниже:
<RadzenDataGrid AllowFiltering = "true" PageSize = "5" Data = "@employees" SelectionMode = "DataGridSelectionMode.Single" @bind-Value = "@selectedEmployees">
<Columns>
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.Id)" Filterable = "false" Title = "ID" Frozen = "true" TextAlign = "TextAlign.Center" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.Name)" Filterable = "true" Title = "Name" Frozen = "true" TextAlign = "TextAlign.Left" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.OrgUnitId)" Filterable = "true" Title = "Org/Unit" Frozen = "true" TextAlign = "TextAlign.Left" />
<RadzenDataGridColumn Property = "@nameof(ApplicationUser.PhoneNumber)" Filterable = "true" Title = "Phone Number" Frozen = "true" TextAlign = "TextAlign.Left" />
</Columns>
</RadzenDataGrid>