ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I work on asp.net mvc auto complete project .I face issue I can't display Employee Name on
input text Id LineManagerName when change auto complete employeeId
Employee Id represent
Employee Name represent
when select employee Id from list of auto complete employee Name not display on input text LineManagerName based on changed id on txtLineManagerId
What I try is
input text Id LineManagerName when change auto complete employeeId
Employee Id represent
input text for employee id:
@Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
input text employee name:
<input type="text" id="LineManagerName" class="form-control" />
What I try is
jquery ajax:
public ActionResult GetAllEmployeeBasedSearchText(string searchText)
{
JDEUtility jde = new JDEUtility();
List<object> employeeListCriteria = new List<object>();
employeeListCriteria = jde.GetAllEmployeeBasedSearchText(searchText);
return Json(employeeListCriteria, JsonRequestBehavior.AllowGet);
}
public static List<object> 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<object> ApplicationsDataValues = new List<object>();
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<string>(0)
});
}
reader.Close();
}
}
con.Close();
return ApplicationsDataValues;
}
catch (Exception e)
{
return new List<object>();
}
}
$(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 };
}))
}
});
}
});
});