I have a select dropdown which I populate content for via a foreach loop off of a list. In one circumstance I want to be able to add a new option to that list and then select that new option. I'm able to add the new value to the list and I'm able to assign the binded property it's new value. I have comments in the output which show the variables are as they should be.
However the UI is not updating prior to the binded property attempting to trigger an on change event leading to the select not selecting the new value but instead what ever the first value of the list is.
I've tried calling stateHasChanged() immediately after updating the list but that doesn't seem to change anything. The specific scenarios logic is occurring in an async Task fired from a button click.
Logic to update the list:
async Task SaveProfile(){
Profiles.Insert(Profiles.Count - 1, new TableConfiguration() { ConfigurationId = NewProfile });
StateHasChanged();
ProfileDecode = NewProfile;
}
Select UI Logic:
<select @bind=ProfileDecode class="form-control-sm">
@foreach (var prof in Profiles)
{
<option>@prof.ConfigurationId</option>
}
</select>
ProfileDecode property
private string ProfileDecode
{
get { return SelectedProfile.ConfigurationId; }
set
{
Console.WriteLine("passed value:" + value + " current value:" + ProfileDecode);
if (SelectedProfile.ConfigurationId != value)
{
SelectedProfile = Profiles.Single(p => p.ConfigurationId == value);
}
}
}