Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery' to type 'PagedList.IPagedList'

asp.net-mvc c# entity-framework-6 pagedlist

Accepted Answer

You do not ascribe the outcomes ofToPagedList() to a variable (and not bringing backIPagedList<PublicReport> , justIEnumerable<PublicReport> (Modify your code to

public ActionResult ListReports(int? page)
{
    var pageNumber = page ?? 1;     
    var listOfReports = db.PublicReport.OrderByDescending(d => d.CreatedDate).Where(c => c.CategoryId == 1).ToList();
     var pagedList = listOfReports.ToPagedList(pageNumber, 3); // modify
     return View("ReportList", pagedList ); // modify
 }

Keep in mind that your model in the view should

@model IPagedList<RENJK.Models.PublicReport>

and the case is then unnecessary. It may only be

@Html.PagedListPager(Model, page => Url.Action(....`
2
5/5/2016 10:15:51 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow