I am adding a PagedList to my view and loosely following this Tutorial. I have installed the PagedList reference using Nuget, set up my controller as follows
public ViewResult Index(int page = 1)
{
List<Part> model = this.db.Parts.ToList();
const int pageSize = 20;
return View(model.ToPagedList(page, pageSize));
}
And written my view with the following model at the top
@model PagedList.IPagedList<RIS.Models.Part>
When I run the page I get the following error
Compiler Error Message: CS0246: The type or namespace name 'PagedList' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 27:
Line 28:
Line 29: public class _Page_Areas_Parts_Views_Part_Index_cshtml : System.Web.Mvc.WebViewPage<PagedList.IPagedList<RIS.Models.Part>> {
The PagedList dll is being properly loaded in my controller because when I take it out of my view everything works as expected. The CopyLocal property is set to 'True' and I have tried including the namespace in the Views\Web.Config in my specific Area. What else can I do to make the View see the Namespace?
In my case, according to the package manager console, my project had a previous reference to PagedList however it was not showing up in my project references in the Solution Explorer.
Solution for me was to use the package manager console to remove PagedList.MVC, then remove PagedList and then re-install them again like so:
uninstall-package PagedList.mvc
uninstall-package PagedList
install-package PagedList
install-package PagedList.mvc
After that everything was good.
Something is messed up with my overall project. I created a new project and copied the important items over and it all works now. I am not sure at all what is wrong with my original project.
FYI for anyone else with the same problem as me here, it was stopping on the controller "using PagedList;" for me (which was correct), however the problem I had was in the view's web.config I had added the namespace reference "PageList" - which was spelled incorrectly! (Should have been PagedList - note the 'd').