Skip to content

Blazor Preview 7 InputSelect Default value #12645

@Julien-Marpault

Description

@Julien-Marpault

I tried to display a default empty optin in a select so I used;

   <InputSelect @bind-Value="@TicketCreateDto.Type">
            <option selected disabled hidden>Type de demande</option>
            @foreach (var item in (TicketType[])Enum.GetValues(typeof(TicketType)))
            {
                <option value="@((int)item)"> @Enumerations.TicketType[(int)item]</option>
            }
        </InputSelect>

Wich isn't working,

I can do it without InputSelect:

 <select name="Type">
            <option selected disabled hidden>Type de demande</option>
            @foreach (var item in (TicketType[])Enum.GetValues(typeof(TicketType)))
            {
                <option value="@((int)item)"> @Enumerations.TicketType[(int)item]</option>
            }
        </select>

But in this case I loose the benfit of model validation

Is there a way to define a default option selected with an empty value ?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions