diff --git a/Project-Unite/Controllers/ForumController.cs b/Project-Unite/Controllers/ForumController.cs index 5b36f20..21fe94a 100644 --- a/Project-Unite/Controllers/ForumController.cs +++ b/Project-Unite/Controllers/ForumController.cs @@ -349,15 +349,15 @@ public static int GetPageCount(this IEnumerable collection, int pageSize) return (collection.Count() + pageSize - 1) / pageSize; } - public static IEnumerable GetItemsOnPage(this IEnumerable collection, int page, int pageSize) + public static T[] GetItemsOnPage(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 obj = new List(); + + for(int i = pageSize * page; i < pageSize + (pageSize * page) && i < collection.Count(); i++) { - yield return lst[i]; + obj.Add(collection[i]); } - + return obj.ToArray(); } } } \ No newline at end of file diff --git a/Project-Unite/Views/Forum/ViewTopic.cshtml b/Project-Unite/Views/Forum/ViewTopic.cshtml index 704566f..eafe240 100644 --- a/Project-Unite/Views/Forum/ViewTopic.cshtml +++ b/Project-Unite/Views/Forum/ViewTopic.cshtml @@ -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(Model.Posts.OrderBy(x => x.PostedAt).ToArray(), ViewBag.Page, ViewBag.PageSize)) { if (Request.IsAuthenticated) {