-
-
Notifications
You must be signed in to change notification settings - Fork 370
Open
Description
When you have more the 4 posts the home page should show a summary of the latest four and display a previous button so that the user can navigate to the earlier posts (assuming of course that your appsettings.json has blog:postsPerPage=4). Unfortunately, the previous button doesn't appear.
There seems to be a bug in views\blog\index.cshtml
@{
int currentPage = int.Parse(ViewContext.RouteData.Values[Constants.page] as string ?? "0");
int pageCount;
pageCount = int.TryParse(ViewData[Constants.TotalPostCount].ToString(), out pageCount) ? 0 : pageCount / 2;
}
When int.TryParse() succeeds pageCount is zero, and when it fails pageCount is zero/2. Therefore I propose the following fix:
- Add to Constants.cs
public static readonly string PostsPerPage = "PostsPerPage";
- Update BlogController.Index() and BlogController.Category()
this.ViewData[Constants.PostsPerPage] = this.settings.Value.PostsPerPage;
- Change Index.cshtml
int currentPage = int.Parse(ViewContext.RouteData.Values[Constants.page] as string ?? "0");
int postsPerPage;
postsPerPage = (int.TryParse(ViewData[Constants.PostsPerPage].ToString(), out postsPerPage) && (postsPerPage > 0)) ? postsPerPage : 4;
int pageCount;
pageCount = int.TryParse(ViewData[Constants.TotalPostCount].ToString(), out pageCount) ? pageCount / postsPerPage : 0;
Metadata
Metadata
Assignees
Labels
No labels