asp-for dropdown code example

Example 1: select asp-items selecte one

@model MyViewModel
<form asp-controller="Home" asp-action="Create">

    <label>Comments</label>
    <input type="text" asp-for="Comments"/>

    <label>Lucky Employee</label>
    <select asp-for="EmployeeId" asp-items="@Model.Employees" >
        <option>Please select one</option>
    </select>

    <input type="submit"/>

</form>

Example 2: dropdown bootstrap

Bootstrap Dropdown menu with seach button<div class="collapse navbar-collapse justify-content-between" id="navbarCollapse">
            <div class="navbar-nav">
                <div class="nav-item dropdown">
                    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">MANAGEMENT</a>
                    <div class="dropdown-menu">
                        <a href="#" class="dropdown-item">Man</a>
                        <a href="#" class="dropdown-item">Man</a>
                        <a href="#" class="dropdown-item">Man</a>
                    </div>
                </div>
            </div>
            
            <div class="collapse navbar-collapse justify-content-between" id="navbarCollapse">
            <div class="navbar-nav">
                <div class="nav-item dropdown">
                    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">PROJECT</a>
                    <div class="dropdown-menu">
                        <a href="#" class="dropdown-item">Pro</a>
                        <a href="#" class="dropdown-item">Pro</a>
                        <a href="#" class="dropdown-item">Pro</a>
                    </div>
                </div>
            </div>

            <div class="navbar-nav">
                <a href="#" class="nav-item nav-link">LOGIN/REGISTER</a>
            </div>
        </div>
    </nav>
</div>

Example 3: asp multi select dropdown

<asp:ListBox runat="server" SelectionMode="Multiple" >
  <asp:ListItem Text="test1"></asp:ListItem>
  <asp:ListItem Text="test2"></asp:ListItem>
  <asp:ListItem Text="test3"></asp:ListItem>
</asp:ListBox>

Example 4: class selector to property in asp net core dropdown

<select data-val="true" data-val-required="The Employee field is required." id="Employee" name="Employee">    <option value=""></option>    <optgroup label="IT">        <option value="1">Mike</option>    </optgroup>    <optgroup label="Sales">        <option value="2">Pete</option>        <option value="4">Dean</option>    </optgroup>    <optgroup label="Admin">        <option value="3">Katy</option>    </optgroup></select>