Dropdown has no items when loaded in OnInitializationAsync

I'm new to Blazor and I'm probably doing this wrong, but I am trying to load data from a database during the OnInitializationAsync and the dropdownlist will not display any data.  How should I accomplish this?

<SfDropDownList TItem="TGame" TValue="string" Placeholder="Select Game" PopupHeight="auto">
  <DropDownListEvents TValue="string" ValueChange="onChange"></DropDownListEvents>
  <DropDownListFieldSettings Value="GameName Text="GameName"></DropDownListFieldSettings>
</SfDropDownList>

@code{

DataContext db = new DataContext();
public List<TGame> Games { get; set; }

protected override async Task OnInitializedAsync()
{
    await base.OnInitializedAsync();
    Games = await db.TGame.ToListAsync();
}


}

3 Replies

PM Ponmani Murugaiyan Syncfusion Team April 8, 2020 03:39 PM UTC

Hi Paul, 

Greetings from Syncfusion support. 

We have validated your reported query. We have prepared sample for load data using OnInitializationAsync. Please find the  code snippet and sample for reference. 

[Index.razor] 
 
<SfDropDownList TItem="Countries" TValue="string" Placeholder="Select a country" PopupHeight="auto" DataSource="@country"> 
    <DropDownListFieldSettings Text="CountryName" Value="CountryId"></DropDownListFieldSettings> 
</SfDropDownList> 
 
@code { 
 
    public List<Countries> country = new List<Countries>(); 
 
    protected override async Task OnInitializedAsync() 
    { 
        country = await Countries.GetAllRecords(); 
    } 
} 
 
 
 
Kindly check with the above sample meets your requirement. Please get back us if you need further assistances. 

Regards, 
Ponmani M 



PA paul April 8, 2020 05:47 PM UTC

Your example helped me isolate where my issue was happening.  It seems my problem had to do with EF Core LazyLoading.  I had to disable lazy loading and also add AsNoTracking to my query.

Thanks


SP Sureshkumar P Syncfusion Team April 9, 2020 04:20 AM UTC

Hi Paul,  
 
Thanks for your update. Please get back to us if you need any assistance on this.  
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon