我正在使用 radzen 数据网格显示 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 Server 作为数据库。我的实现方式有什么问题吗?
根据官方演示(单击“编辑源”),您缺少用
<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>