public async Task <IActionResult> Index(int?index) { index = index ?? 0; if (index > 1) { index = --index; } else { index = 0; } int skipItems = 0; if (index > 0) { skipItems = ApplicationContext.PostsPerPage * (int)index; } else { skipItems = 0; } List <BlogPost> posts = await blog.GetPublishedPosts(ApplicationContext.PostsPerPage, skipItems); int total = blog.GetTotalPostsCount(); BlogViewModel viewModel = new BlogViewModel { Items = posts, TotalPosts = total, PageIndex = ((int)index + 1), TotalPages = total / ApplicationContext.PostsPerPage, HasMorePages = skipItems < total }; return(View(viewModel)); }