I have a select built on json and jquery but the data is concatenated
json
- public async Task<JsonResult> OnGetAssetAsync(string id)
- {
-
- var assets = await _context.WOAssetAssets.Where(s => s.WOALId == id)
- .Select(s => new SelectListItem
- {
- Value = s.WOAId.ToString(),
- Text = s.AssetID + " " + "/" + " " + s.AssetName
- }).ToListAsync();
-
- return new JsonResult(assets);
- }
jquery
- $(function () {
- $("#Asset").on("change", function () {
- var categoryId = $(this).val();
- $("#Equipment").empty();
- $("#Equipment").append("<option value=''>--Select Equipment--</option>");
- $.getJSON(`?handler=Equipment&id=${categoryId}`, (data) => {
- $.each(data, function (i, item) {
- $("#Equipment").append(`<option value="${item.value}"> ${item.text}</option>`);
- });
- $('#Equipment').selectpicker({ liveSearch: true });
- });
- });
- });
and I want to get separate data with
json
- public async Task<JsonResult> OnGetAssetDetailsAsync(string id)
- {
- var asset = await _context.WOAssetAssets.Where(s => s.WOAId == id).SingleOrDefaultAsync();
- return new JsonResult(asset.AssetName, asset.AssetManufacturer);
- }
and updated jquery
- $(function () {
- $("#Asset").on("change", function () {
- var categoryId = $(this).val();
- $("#Equipment").empty();
- $("#Equipment").append("<option value=''>--Select Equipment--</option>");
- $.getJSON(`?handler=Equipment&id=${categoryId}`, (data) => {
- $.each(data, function (i, item) {
- $("#Equipment").append(`<option value="${item.value}"> ${item.text}</option>`);
- });
- $('#Equipment').selectpicker({ liveSearch: true });
- });
- $.getJSON(`?handler=AssetDetails&id =${categoryId}`, (data) => {
- $("#AssetName").append("asset.AssetName");
- $("#AssetManufacturer").append("asset.AssetManufacturer");
- });
- });
- });
but is not working. How should I do it?