I do an auto search on the site my controller is as follows.
public ActionResult AutocompleteSearch(string term) { var a_suppliers = db.Ue_suppliers.Where( a => a.ShortName.Contains(term) || a.Manager.Contains(term) || a.Name.Contains(term) || a.PhoneManager.Contains(term) || a.Phone.Contains(term) ).ToList().Select( a => new { value = a.Manager } ).Distinct(); return Json(a_suppliers, JsonRequestBehavior.AllowGet); }
That is, I transfer the manager without problems, but how do I transfer the data? Visited this a => new { value = a.Manager }
to write a comma, zero reaction
I did everything according to the variant proposed below, everything is fine, but it is tied to the value parameter. Here is my view
<input type="text" name="name" data-autocomplete-source="@Url.Action("AutocompleteSearch", "Uchet")" class="form-control" placeholder="Поиск по " />
But the script below
@section scripts{ <script> $(function () { $("[data-autocomplete-source]").each(function () { var target = $(this); target.autocomplete({ source: target.attr("data-autocomplete-source") }); }); }); </script> }
Everything works fine when you do a => new { value = a.Manager }
, but if I change the controller so that autosearch works on all the fields
public ActionResult AutocompleteSearch(string term) { var a_suppliers = db.Ue_suppliers.Where( a => a.ShortName.Contains(term) || a.Manager.Contains(term) || a.Name.Contains(term) || a.PhoneManager.Contains(term) || a.Phone.Contains(term) ).ToList().Select( a => new { value = a.Manager, a.Name, a.ShortName, a.PhoneManager, a.Phone } ).Distinct(); return Json(a_suppliers, JsonRequestBehavior.AllowGet); }
Then he continues to search only for Managers, but already for the contents of the object.
How can I make auto search work on all records?
new { value = a.Manager, value2 = a.PhoneManager }
so tried using a comma? - Bald