I’m using radzen component to show dropdown, but no data showed up.
<RadzenFormField Text="Class">
<ChildContent>
<RadzenDropDown Data="@MasterClasses"
TextProperty="Name"
ValueProperty="Id"
@bind-Value="@selectedClass"
Placeholder="Please select a class"/>
</ChildContent>
<Helper>
<RadzenRequiredValidator Component="selectedClass" Text="Class is required" />
</Helper>
</RadzenFormField>
@code{
private IEnumerable<MasterClass> MasterClasses;
private int selectedClass;
protected override async Task OnInitializedAsync()
{
MasterClasses = await DbContext.MasterClasses.Select(mc => new MasterClass
{
Id = mc.Id,
ClassroomName = mc.ClassroomName
}).ToListAsync();
await base.OnInitializedAsync();
}
}
I already ensure that all the property has the correct configuration but i dont know why no data is showed up even though there is data in my database. Any idea what might be missing here?
i’m using .NET8 and server side rendermode
The problem is the value you provided to the TextProperty
. There is no Name
property in your MasterClass
class.
With DevTools (F12) Console, you should get the error like:
Unhandled exception rendering component: ‘Name’ is not a member of type ‘+MasterClass’ (Parameter ‘propertyOrFieldName’)
System.ArgumentException: ‘Name’ is not a member of type ‘+MasterClass’ (Parameter ‘propertyOrFieldName’)
Provide the TextProperty
with the value “ClassroomName”.
<RadzenDropDown Data="@MasterClasses"
TextProperty="ClassroomName"
ValueProperty="Id"
@bind-Value="@selectedClass"
Placeholder="Please select a class" />