Я пытался использовать пакет pagedList.mvc для вывода результатов, полученных из запроса, и я сделал это в моем контроллере.Ошибки при использовании PagedList.Mvc
public ActionResult AllPosts()
{
int pageSize = 4;
int pageNum = (page ?? 1);
var query = from p in db.Posts
select new ListPostsVM()
{
PostTitle = p.PostTitle,
Author = p.UserProfile.UserName,
DateCreated = p.DateCreated,
CategoryName = p.Category.CategoryName
};
return View(query.ToPagedList(pageNum, pageSize));
}
и на мой взгляд, я сделал это
@model IPagedList<Blogger.ViewModels.ListPostsVM>
@using PagedList;
@using PagedList.Mvc;
@{
ViewBag.Title = "AllPosts";
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<link href="~/Content/PagedList.css" rel="stylesheet" />
<h2>AllPosts</h2>
<div class="allposts">
<table class="table">
<tr>
<th>Title</th>
<th>Author</th>
<th>Category</th>
<th>Date</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.PostTitle
<p class="actions">
Edit | Delete | View
</p>
</td>
<td>@item.Author</td>
<td>@item.CategoryName</td>
<td>@item.DateCreated</td>
</tr>
}
</table>
</div>
@Html.PagedListPager(Model, page => Url.Action("Index", new { page = page}), PagedListRenderOptions.OnlyShowFivePagesAtATime)
Однако, когда я запускаю построить этот код и я перейти на страницу, я получаю сообщение об ошибке говорящее
An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
Пожалуйста, как мне решить это?