public ActionResult Search(SearchModel model) { using (var context = new NorthwindDataContext()) { var searchResults = context.Products .Where(x => x.ProductName.Contains(model.SearchString)) .ToList(); model.Results = searchResults; return View(model); } }
public ActionResult Search(string query) { SearchModel model = new SearchModel(); if (!string.IsNullOrEmpty(query)) { using (var context = new NorthwindDataContext()) { model.SearchString = query; var searchResults = context.Products .Where(x => x.ProductName.Contains(model.SearchString)) .ToList(); model.Results = searchResults; } } return View(model); }