ASP.NET MVC: search in data entry form -
Thanks for reading more.
I am creating a data entry form. I am trying to understand a way to provide a criterion for the user (for example, last name), the employee table for all employees matches the criteria, can show the result as a way to choose the right employee And the ID of that employee is returned to the data entry form so that they can complete the record and save it.
Thanks
One way to do this is with the jQuery plugin on your form Enter a text box, which allows search and a secret field to store the ID. Use autocomplete via AJAX to get list of names / ID pairs returned as JSON based on search criteria. To compel selection from the list, set up autocomplete - which will reject any non-matching text in the field. When the user selects an item from the list, the result stores the associated ID in the hidden area as a result. AutoFormat ('/ employee / search', {datatype: 'Jason', Max: 25, Min Chairs: 2) (
$ (as '#') , Cache length: 1, match: true, format item: function (data, i, max, value) {return value;}, pars: function (data) {var array = new array (); (var i = 0; i & lt; data. Lamps; i ++) {var data = data [i]; var display = datum.FirstName + '' + datum.ListName; array [array.length] = {data: data, value : Display, result: display}}}}}); $ ('# SearchBox') Results (Tasks (Event, Data, Formatted) {if (Data) {$ ('# employee ID'). Val (Data. EmployeeID);}}); $ ('Form'). Submit (function!) (If!! $ ('# Employee id'). Val ()) {Warning ('You must select an employee before submitting!'); Return return;}}); & Lt; Input type = 'text' id = 'searchbox' / & gt; & Lt; Input type = 'hidden' id = 'employeeID' name = 'employee id' / & gt; Controller:
Public action search (string q, interim) {var query = db.Employees.Where (e => e.LastName .tsts (q)). OrderBe (E = & gt; E.LastNeam). Select (E => New {First Name = E. First Name, Last Name = E.Lostname, Employee ID = E.MPIRE}}; If (range> gt; {} = query.Take (boundary); } Return Jason (query.ToList ()); } Public Action Result Some actions (int comer ID, ...) {...}
Comments
Post a Comment