I have added the following nuget package to my MVC 5 application X.PagedList.Mvc
I return the results in my controller/view as follows:
// Repo
public IPagedList<Post> GetPagedPosts(int pageNumber, int pageSize)
{
var posts = _context.Post
.Include(x => x.Category)
.Include(x => x.Type);
// Return a paged list
return posts.ToPagedList(pageNumber, pageSize);
}
// View model
public class PostViewModel
{
public IPagedList<Post> Posts { get; set; }
...
}
// Controller method
public ActionResult Index(int? page)
{
int pageNumber = page ?? 1;
int pagesize = 5;
var posts = _PostRepository.GetPagedPosts(pageNumber, pagesize);
var viewModel = new PostViewModel
{
Posts = posts,
...
};
return View(viewModel);
}
// View
@model MyApp.ViewModels.PostViewModel
@using X.PagedList.Mvc;
@using X.PagedList;
<p>Page @(Model.Posts.PageCount < Model.Posts.PageNumber ? 0 : Model.Posts.PageNumber) of @Model.Posts.PageCount </p>
But in my view I am getting the following error The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime...
I have no project.json file in my application so what is this error?
System.Runtime
. That can make things screwy – AlibiMicrosoft BCL Portability Pack
? Ensure all of your assembly versions are the same, delete your.suo
and do a clean/build. – Sprague