I\'ve been trying out the PagedList package to get paging for my index views. Everything was going well, and at the controller level everything is working fine, it only disp
As an alternate solution to the accepted answer, remember that IPagedList inherits from IEnumerable. That means that you could write:
@model IEnumerable
At the beginning of the page, and just cast the model to IPagedList when needed:
@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page = page }))
You can even declare the casted variable in the header, in order to use it multiple times within the page:
@{
ViewBag.Title = "My page title";
var pagedlist = (IPagedList)Model;
}
This would allow you to use the DisplayNameFor helper method, and access all PagedList methods/properties, without the need for dummy elements nor calling .FirstOrDefault() for each field.