public ActionResult Index(Guid?locationId) { using (var storeRepo = new StoreLocationRepo(this.db)) using (var carRepo = new CarRepository(this.db)) { List <Car> validCars; StoreLocation store; if (locationId.HasValue) { store = storeRepo.GetStoreById(locationId.Value); validCars = carRepo.CarsByLocationId(locationId.Value, c => c.Manufacturer).ToList(); } else { store = null; validCars = carRepo.AllCars(c => c.Manufacturer).ToList(); } var model = new CarIndexViewModel { Cars = validCars, selectedLocation = store }; return(View("~/Views/Car/Index.cshtml", model)); } }