public JsonResult GetStudents(string term) { AutoCompleteEntities1 db = new AutoCompleteEntities1(); List <string> students = db.tblStudents.Where(s => s.Name.StartsWith(term)) .Select(x => x.Name).ToList(); return(Json(students, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { AutoCompleteEntities1 db = new AutoCompleteEntities1(); var data = db.tblStudents.ToList(); return(View(data)); }
public ActionResult Index(string searchTerm) { AutoCompleteEntities1 db = new AutoCompleteEntities1(); List <tblStudent> students; if (string.IsNullOrEmpty(searchTerm)) { students = db.tblStudents.ToList(); } else { students = db.tblStudents .Where(s => s.Name.StartsWith(searchTerm)).ToList(); } return(View(students)); }