Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

InputSelect first value not working on Blazor Server Side Select dropdown

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...