public void OnGet(bool?isNext = null) { if (isNext == null) { PageIndex = 1; } else { PageIndex = isNext.Value ? PageIndex + 1 : PageIndex - 1; if (PageIndex < 1) { PageIndex = 1; } } AdsToDisplay = _adsService.GetAdsByPage(PageIndex); if (AdsToDisplay.Count == 0) { PageIndex = PageIndex > 1 ? --PageIndex : 1; AdsToDisplay = _adsService.GetAdsByPage(PageIndex); } }