Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
        }