简体   繁体   中英

How to implement Dropdown with searchable in Asp.net mvc or Asp.net Core?

在此处输入图片说明

Note : Here, before you do anything else add this two files in your project select2.css and select2.min.js. Once you have done to added in your project then implement like this way.

Here, I am shown you implement dropdown with searchable using select2.

Add Two files select2.css and select2.min.js

 $(document).ready(function () { $("#ddlDeviceIDs").select2(); $("#ddlDeviceIDs").select2("val", ""); }); function Combo() { $("#ddlDeviceIDs").empty(); $.ajax({ type: "Post", url: "../.../....", contentType: "application/json; charset=utf-8", datatype: "json", acync: false, success: function (data) { var items = '<option value="" disabled selected>--Select DeviceID--</option>'; for (var i = 0; i < data.mdm.length ; i++) { if (parseInt(data.mdm[i].did) == 0) { } else { items += "<option value='" + data.mdm[i].did + "'>" + data.mdm[i].did + "</option>"; } } $("#ddlDeviceIDs").html(items); //if (flag == "1") { //$("#ddlDeviceIDs").val(Code).trigger('change.select2'); //} else { // $("#ddlDeviceIDs").select2("val", ""); // } }, error: function (response) { //alert(response); } }) } If you want to Edit time selection than check this one. $("#ddlDeviceIDs").val(response.lstlicdtl[0].did).trigger('change.select2');
  
<select class="form-control" tabindex=1 id="ddlDeviceIDs"></select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM