// GET: Ride public ActionResult Index(int?campusId, string dayOfWeek) { IQueryable <Ride> ridesQuery = db.Rides.Include(r => r.Campus); if (campusId.HasValue) { ridesQuery = ridesQuery.Where(r => r.CampusId == campusId); } if (dayOfWeek != null) { ridesQuery = ridesQuery.Where(r => r.DayOfWeek == dayOfWeek); } var model = new RideIndexModel { Rides = ridesQuery , Campuses = db.Campus.Select(c => new SelectListItem { Value = c.CampusId.ToString(), Text = c.Name }) , DaysOfWeek = new List <SelectListItem> { new SelectListItem { Value = "Sunday", Text = "Sunday" } , new SelectListItem { Value = "Monday", Text = "Monday" } , new SelectListItem { Value = "Tuesday", Text = "Tuesday" } , new SelectListItem { Value = "Wednesday", Text = "Wednesday" } , new SelectListItem { Value = "Thursday", Text = "Thursday" } , new SelectListItem { Value = "Friday", Text = "Friday" } , new SelectListItem { Value = "Saturday", Text = "Saturday" } } }; return(View(model)); }
// Ride/Search public ActionResult Search(RideIndexModel query) { return(RedirectToAction("Index", new { campusId = query?.SelectedCampusId, dayOfWeek = query?.SelectedDayOfWeek })); }