Question Value of employee name not display based on employee id autocomplete?

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

input text for employee id:
@Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
Employee Name represent

input text employee name:
<input type="text" id="LineManagerName" class="form-control" />
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

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 };



                        }))



                    }

                });

            }

        });

    });
 
I don't fully understand the problem yet, but just skimming the 3rd chunk of code above, how is that code even compiling? Line 1 and line 19 look to be declaring the same method name with the same parameter type, but just different return types. As far as I know, C# doesn't support that kind of method overloading.
 
I work on asp.net mvc . i face issue employee name display based on auto complete selection

and after select employee id from auto complete employee name display based on selection employee id

after click submit button create action fire and page load but employee name not display so

How to solve this issue please

full code details
full code details html and controller:
@model HR.WorkforceRequisition.Models.ResignationRequester


@{
    ViewBag.Title = "Create";
}


@using (Html.BeginForm("Create", "Resignation", FormMethod.Post, new { enctype = "multipart/form-data", @id = "mainform", style = "padding-top: 50px" }))
{




    <div class="form-horizontal">
      

        <div class="row">
            <div class="form-group col-md-6 hover">
                <div class="col-md-5">
                    @Html.LabelFor(model => model.LineManager, htmlAttributes: new { @class = "control-label" })
                    <span class="text-danger"> *</span>
                </div>

                <div class="col-md-7">
                    @Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
                </div>
            </div>
          
            </div>

        </div>


        <div class="row">
            <div class="form-group col-md-6 hover">
                <div class="col-md-5">
                    @Html.Label("Line Manager Name", htmlAttributes: new { @class = "control-label" })
                </div>

                <div class="col-md-7">
                    <input type="text" id="LineManagerName" class="form-control" />
                  
                </div>
            </div>
          

        </div>
        <div id="searchContainer">

        </div>

        <div id="searchContainerDirector" style="margin-left:900px;">

        </div>

        



        <div class="form-group">
            <div class="col-md-offset-0 col-md-12">
                <input type="submit" value="Submit" class="btn btn-success" />
            </div>
        </div>




    </div>
}


<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"
        language="javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>


    $(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 };

                        }))

                    }
                });
            },
            position: { my: "right top", at: "right bottom" },
            appendTo: '#searchContainer',
            select: function (event, ui) {

                $("#LineManagerName").val(ui.item.employeeName);
            }
      
        });

      



</script>


public class ResignationController : Controller
    {
 public ActionResult GetAllEmployeeBasedSearchText(string searchText)
        {
            JDEUtility jde = new JDEUtility();
        
            List<object> employeeListCriteria = new List<object>();
            employeeListCriteria = jde.GetAllEmployeeBasedSearchText(searchText);
            return Json(employeeListCriteria, JsonRequestBehavior.AllowGet);

        }
     }
 [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Create(ResignationRequester resignationRequester)
        {
        return View(resignationRequester);
        }

image show issue details

Issue after create submit.png
 
You already have a thread about this. Merging into your old thread.
 
This is a volunteer forum. People jump into topics as their time and interest allows.

What you can do is supply the minimal amount of code to reproduce the problem. That may intice someone to look over the code and even try to copy and paste the code into their machine to play with it. The easier you make it for someone to help you, the bigger the chances that someone may jump in.

As an aside, from personal experience, I have found that in about 70% of the time while I am preparing code to show a minimal repro case, I end up understanding the problem better and end up solving my own problem.
 
I'd love to help but I've put the trauma of webforms well behind me. Sounds like youre not populating the textfield when the page is sent back out to the user ; I don't recall it happening automatically

Why have yo uused @Html.EditorFor for the number, but a plain <input type=text for the name?
 

Latest posts

Back
Top Bottom