Set Default/Null Value with Select TagHelper

You can just insert an option item inside the select:

<select asp-for="Category" asp-items="@ViewBag.Category"  class="form-control">
    <option disabled selected>--- SELECT ---</option>
</select>

The disabled keyword in the code above means that the “— SELECT —” row cannot be picked again once a choice has been selected in the list. If you want the user to be able to blank the selection again (i.e. if it’s bound to a nullable field) then just omit disabled.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)