Marius Vasile

Marius Vasile

  • 590
  • 1.9k
  • 148.7k

asp.net core passing jquery val as asp-route-id parameter

Feb 24 2021 5:01 PM
I have the following jquery
 
  1. $(function () {  
  2.     $("#Asset").on("change", function () {  
  3.         var categoryId = $(this).val();  
  4.         $("#Equipment").empty();  
  5.         $("#Equipment").append("<option value=''>--Select Equipment--</option>");  
  6.         $.getJSON(`?handler=Equipment&id=${categoryId}`, (data) => {  
  7.             $.each(data, function (i, item) {  
  8.                 $("#Equipment").append(`<option value="${item.value}"> ${item.text}</option>`);  
  9.             });  
  10.             $('#Equipment').selectpicker({ liveSearch: true });  
  11.         });  
  12.         $.getJSON(`?handler=AssetDetails&id=${categoryId}`, (data) => {  
  13.             if (!jQuery.isEmptyObject(data)) {  
  14.                 $("#AssetID").val(data.assetID);  
  15.                 $("#AssetName").val(data.assetName);  
  16.                 $("#AssetManufacturer").val(data.assetManufacturer);  
  17.             }  
  18.         });   
  19.     });  
  20. });  
and a button
 
  1. <button class="btn form-control" type="submit" asp-page-handler="Test" asp-route-id="id" id="testid">Button</button>  
 
 Select
 
  1. <div class="col-md-5">  
  2.             <select id="Asset" class="form-control" asp-items="@(new SelectList(string.Empty, "WOAId", "AssetID", "AssetName", "AssetManufacturer"))" data-style="border-warning bg-transparent">  
  3.                 <option value="">--Select Asset--</option>  
  4.             </select>  
  5.               
  6.         </div>  
 
 
How do I pass $("#AssetID").val(data.assetID); as id in button asp-route-id?
 

Answers (10)