Radzen Blazor下拉菜单从外部API的动态数据



我从外部API获取数据,代码看起来像这样(这部分很好):

@code {
IEnumerable<IDictionary<string, object>> data;
int count;
bool isLoading;
async Task LoadData(LoadDataArgs args)
{
isLoading = true;
var uri = new Uri("https://services.radzen.com/odata/Northwind/Employees")
.GetODataUri(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);
var response = await new HttpClient().SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));
var result = await response.ReadAsync<ODataServiceResult<IDictionary<string, object>>>();
data = result.Value.AsODataEnumerable();
count = result.Count;
isLoading = false;
}
}

在下拉菜单上,我想显示EmployeeID,但无法访问它(Data="@data.Employee.ID"是不正确的,而且不确定要在里面放什么才能使它工作)。

<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="string">
</RadzenDropDown>

谢谢!

问题是数据属性是:

IEnumerable<IDictionary<string, object>> data;

应该是:

IEnumerable<Employee>data;

这样你就可以访问Employee类的属性了

<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="Employee">
</RadzenDropDown>

最新更新