Dropdown does not keep the selection
Dmitriy Reznik
236
Reputation points
I have a blazor server-side application with a drop-down on a page:
<EditForm Model="@_dummyEditModel" class="my-4 dropdown-parts">
<InputSelect id="products" @bind-Value="_selectedProductId" class="form-control">
<option value="@((short)Product.None)">--Select Product--</option>
@foreach (QuoteTypeModel product in _products)
{
<option value="@product.Id">@product.Name</option>
}
</InputSelect>
</EditForm>
In the code-behind:
private Product _selectedProductId = Product.None;
...
public enum Product { None = 0, ShowerPan = 1, LinearDrain = 2, Bench = 3, Niche = 4, Curb = 5 }
When I run the application, and select an element in the drop-down, the selection appears for a moment, and immediately disappears, leaving the selection empty (though _selectedProductId is assigned correctly). When I select the same element again, the selection stays.
If I make the type of _selectedProductId int instead of enum Product, the drop-down works as expected.
How can I fix this behavior?