TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
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
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
592
1.9k
150.1k
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