Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

First option is always null in InputSelect

$
0
0

In my Blazor app, the <InputSelect /> component is not working as expected. The first option is being shown as selected, but when I submit the form it is always null.

Relevant Model properties:

public int? Distance { get; set; }public Dictionary<int, string> DistanceList { get; set; }//Set in the constructorDistanceList = new Dictionary<int, string>(){    { 5, "5 Miles" },    { 10, "10 Miles" },    { 25, "25 Miles" }};

Select List:

<InputSelect @bind-Value="model.Distance">    @foreach (var distance in model.DistanceList)    {<option value=@distance.Key>@distance.Value</option>                                                                }</InputSelect>

If I select "10 Miles" or "25 Miles" first, then select "5 miles", then submit the form, Distance will be 5 miles. But if I just submit the form, Distance is null. Even though, 5 miles is selected.


Viewing all articles
Browse latest Browse all 4839

Trending Articles