0

I am trying to use the packaged PagedList.MVC to try and force my data into splitting into pages. However I get so far in the controller and then receive the above error and another error is given below:

The best overloaded method match for 'PagedList.PagedList.PagedList(System.Collections.Generic.IEnumerable<ViewModel>, int, int)' has some invalid arguments

But, I think this error will be fixed once my first error is solved.

Can anybody help me with the problem?

Controller:

public ActionResult SupplierReportSelection(int ClientID, int? SupplierID = null, int? ReviewPeriodID = null, int page = 1)
{
    ClaimsBySupplierViewModel SupplierModel = ClaimsBySupplier(ClientID, SupplierID, ReviewPeriodID);

    int pageSize = 10;
    int pageNumber = (page);

    PagedList<ClaimsBySupplierViewModel> model = new PagedList<ClaimsBySupplierViewModel>(SupplierModel, page, pageSize);
    ViewBag.client = client;

    return View("ClaimsBySupplier", model);
} 

ViewModel:

public class ClaimsBySupplierViewModel : ReportViewModel {
        public IQueryable<ClaimsBySupplierReport> ReportData { get; set; }
        public IQueryable<SupplierAndClaimNumberReviewTotalsByStatusCategory> ReportTotalData { get; set; }
        public decimal? Conversion { get; set; }
    }
Andrew Kilburn
  • 2,251
  • 6
  • 33
  • 65
  • So what exactly are you wanting to "page"? The `ReportData` or the `ReportTotalData`? `PagedList` only "pages" one collection, so it's not clear what you intend to show in the view. – D Stanley Jul 17 '15 at 15:48
  • Sorry, ReportData and ReportTotalData both contain a collection of my model. I just want to split the results into pages to ease loading times – Andrew Kilburn Jul 17 '15 at 15:51
  • I have updated my answer, you were referencing the model as a whole but needed to specify which list. – Chad Jul 17 '15 at 15:51
  • I just saw your comment right before my last, if you want both lists to display on the same page but as paged lists, just combine the lists with Linq or in your repository where you are populating the lists. – Chad Jul 17 '15 at 15:53
  • I don't want to do either, I just want to display one list of ClaimsBySupplierViewModel which contains my model, ClaimsBySupplierModel. I would then like to split this list into pages – Andrew Kilburn Jul 17 '15 at 15:55
  • I did some research on the differences between IQueryable and IEnumerable. In your model, you will need to change IQueryable to IEnumerable to fix the syntax error. For a good comparison of IQueryable vs IEnumerable, read the first answer here: http://stackoverflow.com/questions/2876616/returning-ienumerablet-vs-iqueryablet – Chad Jul 17 '15 at 15:58

1 Answers1

2

The PagedList is looking for an IEnumerable object, such as a List of objects.

Being that your SupplierModel looks specific to one object with properties, that is what is causing your issue.

After seeing your Model's code, what you will want to do is reference your model's List of data you want to show, not just your model itself.

And instead of instantiating a PagedList object, return the view with the List of your data.

return View("ClaimsBySupplier", SupplierModel.ReportData.ToPagedList(page, pageSize);
Chad
  • 872
  • 8
  • 24
  • Thanks for the reply. However, even I implement the problem, I still get the same issue. Is this because I need to have a paged list of my model and not my view model as I only have one view model which contains a collection of one model – Andrew Kilburn Jul 17 '15 at 15:52