In Blazor / C# / ASP.NET Core 8.0, I am trying to load the InputSelect
with the list when it is clicked, but I am not able to do it.
Actually I want to make something like multiple InputSelect
s. Let’s say venues.
And if one item is selected in one InputSelect
, I want it not to appear in other InputSelect
s – is this even possible?
I am using .NET 8.0 and it is a Blazor Server project.
@rendermode InteractiveServer
<div>
<InputSelect @bind-Value=SelectedVenue style="width:100px" @onfocus="LoadVenuesOnClick">
@foreach (var venue in venueNames)
{
<option value="@venue">@venue</option>
}
</InputSelect>
</div>
private void LoadVenuesOnClick()
{
List<string> venueNames = venueDL_GLOBAL.GetAvailableVenues(Hour, Day, MainHall);
if (venueNames!=null)
this.venueNames.AddRange(venueNames);
}
private List<string> venueNames = new() { "None" };
private string SelectedVenue = "None";
I have tried to do with @onselect
, but it is not working:
<InputSelect @bind-Value=SelectedVenue style="width:100px" @onselect="LoadVenuesOnClick">
Also I did tried to add StateHasChanged();
to notify Blazor to re-render the component, in the LoadVenuesOnClick()
function.
2
Answers
In my parent component, this was missing that is why it was not working. Otherwise it is working fine.
I don’t exactly understand what you’re trying to do. Maybe the following will give you some ideas. Probably seeing how I used Linq to filter the available venues with
.Where()
and.Contains()
might help. I use those constantly on almost every page involving data.