Select field with first blank item

Asked

Viewed 89 times

0

Utilise select and it comes filled from the bank:

    <select asp-for="CategoriaID" asp-items="@Model.CountryList" id="cbcategoria" class="form-control">
                    </select>

And here’s how it’s in the controller:

model.CountryList = new SelectList(countries, "Id", "Value");

Would you like to know how I can leave select without filling in when entering a new record? The field is required in Viewmodel.

2 answers

1

From what I understand you want the first item of select to be white, you can do in the page load.

$("#cbcategoria").append("<option id='option_cbcategoria' value='' selected>" + "" + " </option>");

1


You can add an option with the option disabled so that he is not selected.

<select asp-for="CategoriaID" asp-items="@Model.CountryList" id="cbcategoria" class="form-control">
    <option disabled selected>Selecione</option>
</select>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.