I work on asp.net mvc auto complete project .I face issue I can't display EmployeeName on input text Id LineManagerName when change auto complete employeeId
list of employeeid auto complete display success but I can't get employeename for selected employee id on input text LineManagerName
code working success and auto complete working perfect only need to display Employee Name when employeeId changed
TypeScript
@Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
public ActionResult GetAllEmployeeBasedSearchText(string searchText)
{
JDEUtility jde = new JDEUtility();
List employeeListCriteria = new List();
employeeListCriteria = jde.GetAllEmployeeBasedSearchText(searchText);
return Json(employeeListCriteria, JsonRequestBehavior.AllowGet);
}
public static List GetAllEmployeeBasedSearchText(string searchText)
{
OleDbConnection con = new OleDbConnection(connectionString);
string query = "";
query = "SELECT cast(EMP.YAAN8 as varchar(20)) as EmployeeID,EMP.YAALPH AS EmployeeName FROM CRPDTA.F060116 EMP WHERE cast(EMP.YAAN8 as varchar(20)) LIKE '%" + searchText + "%' WITH UR";
List ApplicationsDataValues = new List();
try
{
using (var command = con.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
command.Connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
ApplicationsDataValues.Add(new
{
EmployeeID = reader.GetFieldValue(0)
});
}
reader.Close();
}
}
con.Close();
return ApplicationsDataValues;
}
catch (Exception e)
{
return new List();
}
}
$(document).ready(function () {
$("#txtLineManagerId").autocomplete({
source: function (request, response) {
var searchText = $("#txtLineManagerId").val();
console.log("search text" + searchText)
$.ajax({
url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")',
data: { searchText: searchText },
method: "GET",
dataType: "json",
success: function (data) {
response($.map(data, function (item) {
console.log("data is" + item.EmployeeID);
return { label: item.EmployeeID, value: item.EmployeeID };
}))
}
});
}
});
});
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 24, 2023, 12:23 AM EDT
$(document).ready(function () { $("#txtLineManagerId").autocomplete({ source: function (request, response) { var searchText = $("#txtLineManagerId").val(); console.log("search text" + searchText); $.ajax({ url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")', data: { searchText: searchText }, method: "GET", dataType: "json", success: function (data) { response($.map(data, function (item) { console.log("data is" + item.EmployeeID); return { label: item.EmployeeID, value: item.EmployeeID, employeeName: item.EmployeeName }; })); } }); }, select: function (event, ui) { // Update LineManagerName input with the selected Employee Name $("#LineManagerName").val(ui.item.employeeName); } }); });