fix pagination

This commit is contained in:
Michael 2017-04-20 11:24:19 -04:00
parent f5c33c367a
commit 66e3da8b2e
2 changed files with 7 additions and 7 deletions

View file

@ -349,15 +349,15 @@ public static int GetPageCount<T>(this IEnumerable<T> collection, int pageSize)
return (collection.Count() + pageSize - 1) / pageSize;
}
public static IEnumerable<T> GetItemsOnPage<T>(this IEnumerable<T> collection, int page, int pageSize)
public static T[] GetItemsOnPage<T>(this T[] collection, int page, int pageSize)
{
var lst = collection.ToList();
for(int i = pageSize * page; i < pageSize + (pageSize * page) && i < lst.Count(); i++)
List<T> obj = new List<T>();
for(int i = pageSize * page; i < pageSize + (pageSize * page) && i < collection.Count(); i++)
{
yield return lst[i];
obj.Add(collection[i]);
}
return obj.ToArray();
}
}
}

View file

@ -31,7 +31,7 @@
Html.RenderPartial("~/Views/Shared/_ModeratorBar.cshtml", Model);
}
@foreach (var post in Model.Posts.OrderBy(x => x.PostedAt).GetItemsOnPage(ViewBag.Page, ViewBag.PageSize))
@foreach (Project_Unite.Models.ForumPost post in PaginationExtensions.GetItemsOnPage<Project_Unite.Models.ForumPost>(Model.Posts.OrderBy(x => x.PostedAt).ToArray(), ViewBag.Page, ViewBag.PageSize))
{
if (Request.IsAuthenticated)
{