Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forumguidelines
Marius Vasile
1.4k
657
7.9k
asp.net core get additional info with json and jquery
Jan 30 2021 5:28 AM
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?
Reply
Answers (
10
)
ASP.net on Mouse click submenu items should appear
Textarea does not support hyperlink in asp.net core