// GET: Cars public ActionResult Index() { try { IQueryable <Car> cars = db.Cars; if (cars != null) { CarsIndexViewModel model = new CarsIndexViewModel() { Makes = cars.Select(c => new SelectListItem() { Value = c.make, Text = c.make }).Distinct().ToList(), Models = new List <SelectListItem>(), GridModel = new CarGridViewModel() { Cars = PagedListHelpers.GetNextCars(null, null, null, 0, 10) } }; return(View(model)); } else { throw new Exception("The 'Car' entity result collection is null.", new NoNullAllowedException()); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Cars", "Index"))); } }
public ActionResult GetNextCars(string make, string model, string term, int?page, int pageSize = 10) { try { var pageIndex = page - 1 ?? 0; CarGridViewModel returnModel = new CarGridViewModel() { Cars = PagedListHelpers.GetNextCars(make, model, term, pageIndex, pageSize), Make = make, Model = model, Term = term }; if (returnModel != null) { return(PartialView("_CarsGrid", returnModel)); } else { throw new Exception("The 'CarGridViewModel' object containing the 'Car' entity result collection is null.", new NoNullAllowedException()); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Cars", "Index"))); } }
public ActionResult SearchCars(string term) { try { CarGridViewModel model = new CarGridViewModel() { Cars = PagedListHelpers.GetNextCars(null, null, term, 0, 10), Term = term }; if (model != null) { return(PartialView("_CarsGrid", model)); } else { throw new Exception("The 'CarGridViewModel' object containing the 'Car' entity result collection is null.", new NoNullAllowedException()); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Cars", "Index"))); } }