public IActionResult Index(string activeConf = "all", string activeDiv = "all") { var session = new NFLSession(HttpContext.Session); session.SetActiveConference(activeConf); session.SetActiveDivision(activeDiv); int?count = session.GetTeamCount(); if (count == null) { var cookies = new NFLCookies(Request.Cookies); string[] ids = cookies.GetTeamsIds(); List <Team> myTeams = new List <Team>(); if (ids.Length > 0) { myTeams = _ctx.Teams.Include(c => c.Conference) .Include(d => d.Division) .Where(t => ids.Contains(t.TeamID)) .ToList(); } //this preserves the state of the cookies even after the browser has been closed...as long as it doesn't exceed 10days session.SetTeams(myTeams); } var data = new TeamListViewModel { ActiveConference = activeConf, ActiveDivision = activeDiv, Conferences = _ctx.Conferences.ToList(), Divisions = _ctx.Divisions.ToList() }; IEnumerable <Team> query = _ctx.Teams; if (activeConf != "all") { query = query.Where(t => t.Conference.ConferenceID.ToLower() == activeConf.ToLower()); } if (activeDiv != "all") { query = query.Where(d => d.Division.DivisionID.ToLower() == activeDiv.ToLower()); } data.Teams = query.ToList(); return(View(data)); }