Marius Vasile

Marius Vasile

  • 602
  • 1.7k
  • 124.5k

asp.net core combine select, javascript and bootstrap-select

Jan 25 2021 2:26 PM
I have a cascade select
 
  1. <select id="Location" class="form-control border-warning selectpicker" asp-items="Model.Locations" OnChange="func1()">  
  2.                     <option value="">--Select Asset Location--</option>  
  3.                 </select>  
  4.   
  5. <select id="Asset" class="form-control border-warning selectpicker" asp-items="@(new SelectList(string.Empty, "WOAId", "AssetID", "AssetName"))" OnChange="func2()">  
  6.                     <option value="">--Select Asset--</option>  
  7.                 </select>  
and getting the value for the second select with
 
  1. $("#Location").on("change", function () {  
  2.         var categoryId = $(this).val();  
  3.         $("#Asset").empty();  
  4.         $("#Asset").append("<option value=''>--Select Asset--</option>");  
  5.         $.getJSON(`?handler=Asset&id=${categoryId}`, (data) => {  
  6.             $.each(data, function (i, item) {  
  7.                 $("#Asset").append(`<option value="${item.value}"> ${item.text}</option>`);  
  8.             });  
  9.         });  
  10.     });  
 How do I include bootstrap-select into the above?
 
  1. $('#Location').selectpicker({  
  2.                 liveSearch: true  
  3.             });  
  4.   
  5. $('#Asset').selectpicker({  
  6.                 liveSearch: true  
  7.             });  
 

Answers (8)