public ActionResult Index(StaticDataViewModel parkStateList) { List <SelectListItem> selectListItems = _parkService.GetStatesWithParks(); List <Park> parksList = _parkService.GetParks(); SelectListItem selected = selectListItems.Where(l => l.Value == parkStateList.ParkObj.ParkState).First(); StaticDataViewModel parksViewModel = new StaticDataViewModel { States = selectListItems, // Returns only states where Parks exist FilteredParkList = parksList.Where(p => p.ParkState == selected.Value).ToList() }; return(View(parksViewModel)); }
// GET: ParkController public ActionResult Index() { try { List <Park> parks = _parkService.GetParks(); List <SelectListItem> selectListItems = _parkService.GetStatesWithParks(); StaticDataViewModel parksViewModel = new StaticDataViewModel { Park = parks, // List of all Parks ---- used to list all trails on the view States = selectListItems, // Returns only states where Parks exist ParkObj = null, FilteredParkList = parks }; return(View(parksViewModel)); } catch { return(View()); } }