[HttpGet] //ID is the page number coming in public async Task <IActionResult> Index(int?ID) { //Set to ID. If ID is null, set to 1 int page = ID ?? 1; const int PageSize = 3; List <VideoGame> games = await VideoGameDB.GetGamesByPage(context, page, PageSize); int totalPages = await VideoGameDB.GetTotalPages(context, PageSize); ViewData["Pages"] = totalPages; ViewData["CurrentPage"] = page; return(View(games)); }
[HttpGet] //id is the page number coming in public async Task <IActionResult> Index(int?id) { //Null-coalescing operator // If id is not null set page to it, or if null use 1 int page = id ?? 1; //id is the page number coming in const int PageSize = 3; List <VideoGame> games = await VideoGameDB.GetGamesByPage(_context, page, PageSize); int TotalPages = await VideoGameDB.GetTotalPages(_context, PageSize); ViewData["Pages"] = TotalPages; ViewData["CurrentPage"] = page; return(View(games)); }