asp.net-core-mvcdropdownasp.net-core-6.0

Editable dropdown box in ASP.NET Core 6 MVC


I have ASP.NET Core 6 project. I need an editable dropdown box in one of the views. I tried datalist & javascript autocomplete functionality but both of them not working.

My code in view is :

<input type="text" name="medCompany" id="medCompany" list="ddlmedCompany" class="form-control form-control-lg" />
<datalist id="ddlmedCompany" class="form-control form-control-lg" >
@foreach (var item in Model.lstmedCompany)
{
    <option>@item.Text</option>
}
</datalist>

But this gives look as below:

enter image description here

and dropdwon box is :

enter image description here

What I need is only dropdown box and not test box which is displayed below dropdown box. How can I achieve this?


Solution

  • Try to remove class="form-control form-control-lg" from datalist

      <input type="text" name="medCompany" id="medCompany" list="ddlmedCompany"  class="form-control form-control-lg" />
     <datalist id="ddlmedCompany"  >
            @foreach (var item in Model.lstmedCompany)
             {
               <option>@item.Text</option>
              }
       </datalist>