无法将ViewModel转换为Generic IEnumerable ViewModel

时间:2015-07-17 15:36:39

标签: c# asp.net-mvc pagination

我正在尝试使用打包的PagedList.MVC来尝试强制我的数据分成页面。但是我在 controller 中到目前为止,然后收到上述错误,下面给出了另一个错误:

  

'PagedList.PagedList.PagedList(System.Collections.Generic.IEnumerable< ViewModel>,int,int)'的最佳重载方法匹配有一些无效的参数

但是,我认为一旦我的第一个错误得到解决,这个错误就会被解决。

有人可以帮我解决这个问题吗?

控制器:

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);
} 

视图模型:

public class ClaimsBySupplierViewModel : ReportViewModel {
        public IQueryable<ClaimsBySupplierReport> ReportData { get; set; }
        public IQueryable<SupplierAndClaimNumberReviewTotalsByStatusCategory> ReportTotalData { get; set; }
        public decimal? Conversion { get; set; }
    }

1 个答案:

答案 0 :(得分:2)

PagedList正在寻找IEnumerable对象,例如对象列表。

由于您的SupplierModel看起来特定于具有属性的一个对象,因此导致您的问题。

在看到您的模型代码后,您要做的是引用您想要显示的模型的数据列表,而不仅仅是模型本身。

而不是实例化PagedList对象,而是返回包含数据列表的视图。

return View("ClaimsBySupplier", SupplierModel.ReportData.ToPagedList(page, pageSize);
相关问题