mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
fix pagination
This commit is contained in:
parent
f5c33c367a
commit
66e3da8b2e
2 changed files with 7 additions and 7 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue