Autocomplete in ASP.NET MVC3自动检索并填充输入框

1、单一产品情况下使用:


public ActionResult GetStockList()
{
    var item = _db.Stocks.ToList().Select(s =>s.Product.CodePro);
    return Json(item, JsonRequestBehavior.AllowGet);
}



 2、多组返回值的情况下:





Find by name: @Html.TextBox("SearchString")

 public ActionResult AutocompleteSuggestions(string term)
{
  var suggestions = db.Students.Select(s => new { label = s.LastName+"|"+s.FirstMidName, value = s.StudentID}).Where(b=>b.label.ToLower().StartsWith(term.ToLower()));
  return Json(suggestions, JsonRequestBehavior.AllowGet);
}



你可能感兴趣的:(C#)