Hi,
I am using MVC and asp.net core.
I'm trying to display an autocomplete, retrieving an Employee Object (Employee Id, Last Name, First Name) from database and returning json.
The dropdownlist is returning [ undefined ] - [ undefined ]. How can it return the right output?
Thanks,
tinac99
View
<script type="text/javascript">
$(document).ready(function () {
$("#RequestingEmployeeFName").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Employee/SearchEmployee",
type: "GET",
dataType: "json",
data: {
EmployeeId: null,
EmployeeFirstName: request.term,
EmployeeLastName: null
},
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data, function (item) {
return {
label: item.EmplId + " - "
+ item.EmplLastName
};
}));
}
});
}
});
});
ViewModel
public class EmployeeViewModel
{
public string EmplId { get; set; }
public string EmplLastName { get; set; }
public string EmplFirstName { get; set; }
}
EmployeeController
public JsonResult SearchEmployee(string EmployeeId, string EmployeeLastName, string EmployeeFirstName)
{
List<EmployeeViewModel> empList = _employeeRepository.Find(EmployeeId, EmployeeLastName, EmployeeFirstName);
List<String> emps = empList.Select(item => item.EmplLastName).ToList();
return Json(empList);
}