I have the following in a cs code behind of a razor component.
private MyObject myObject{ get; set; } = new MyObject();
private async Task HandleCreateMyObject()
{
var MyObjectCreated = await myObjectService.CreateNewMyObject(myObject);
if (MyObjectCreated != null)
{
NavigationManager.NavigateTo("/myobjects/" + MyObjectCreated.Id);
}
}
I have an enum:
public enum StatusEnum
{
New,
Active,
Closed
}
My razor component select dropdown is this:
<InputSelect class="form-control" @bind-Value="myObject.Status">
@foreach (var status in StatusEnum.GetValues(typeof(StatusEnum)))
{
<option value="@status">@status</option>
}
</InputSelect>
MyObject.status
is a string.
If I choose the first option in the select dropdown (which populates the list of enums), it passes null to myObject
. Any other option does pass correctly. Any thoughts on why status[0] = null on the bind? Inspecting the html, I can see it looks solid. There's an <option value="xyz">xyz</option>
question from:
https://stackoverflow.com/questions/65944220/inputselect-first-value-not-working-on-blazor-server-side-select-dropdown 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…