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
594
1.9k
144.8k
asp.net core textbox autocomplete with jquery and json
May 16 2021 5:41 PM
I am trying to have a textbox with autocomplete using an example from here https://www.iaspnetcore.com/blog/blogpost/577e6e3784cd461ac830e4a9. However, I get no results. My code below
<div
class
=
"col-md-1"
>
<select id=
"ConClass"
class
=
"form-control border-danger"
asp-items=
"@Model.SelectControlClass"
>
<option value=
""
>-- Select --</option>
</select>
<span asp-validation-
for
=
"RiskAssessmentSecondary.ConClass"
class
=
"text-danger"
></span>
<input asp-
for
=
"RiskAssessmentSecondary.ConClass"
id=
"conClass"
/>
</div>
<div
class
=
"col-md-2"
>
<input id=
"txtControl"
type=
"text"
class
=
"form-control"
asp-
for
=
"RiskAssessmentSecondary.ConDetail"
/>
<span asp-validation-
for
=
"RiskAssessmentSecondary.ConDetail"
class
=
"text-danger"
></span>
</div>
$(
function
() {
$(
"#ConClass"
).on(
"change"
,
function
() {
var
data = $(
"#ConClass :selected"
).text();
$(
"#conClass"
).val(data);
$(
"#txtControl"
).autocomplete({
source:
function
(request, response) {
$.getJSON(`?handler=AutoComplete`, request,
function
(data) {
response($.map(data,
function
(item) {
return
{
value: item +
""
}
}))
})
}
});
});
});
public
JsonResult OnGetAutoComplete(
string
id)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var orgid = _context.UsersData.Where(a => a.Id == userId).Select(a => a.OrgID).SingleOrDefault();
var conDetail = (from a
in
_context.HazardSources.Where(s => s.OrgID == orgid)
join b
in
_context.HazardClasses on a.IdHS equals b.IdHS into Temp1
from c
in
Temp1
join d
in
_context.HazardDetails on c.IdHC equals d.IdHC into Temp2
from e
in
Temp2
join f
in
_context.ControlClasses.Where(s => s.ConClass.ToLower().Contains(id.ToLower())) on e.IdH equals f.IdH into Temp3
from g
in
Temp3 select
new
{
value = g.ConDetail
}).Distinct().ToList();
return
new
JsonResult(conDetail);
}
Reply
Answers (
1
)
asp.net core jquery not functioning when ddl is empty
How can i get already stored image path in web api via postman