ASP.NET MVC: search in data entry form

前端 未结 3 764
感动是毒
感动是毒 2021-02-10 16:39

and thanks for reading.

I am building a data entry form. I am trying to figure out a way to let the user to provide a criteria (last name for instance), search the emplo

3条回答
  •  旧时难觅i
    2021-02-10 17:08

    Something like this in the controller to search in the database (using linq) ?

    public ActionResult searchEmployees(string searchString) {
            var employees = (from e in db.Employees
                                   where e.Name.Contains(searchString)
                                   orderby e.Name
                                   select e);
            return view("SearchResult", employees);
    }
    

    EDIT: Just read your comments and if I understand correctly, you're only interested in the id's. Are you using those in javascript, and is this some kind of ajax call ? In that case you might want to return an array, or a csv string and deal with the id's in the javascript call.

提交回复
热议问题