传递到字典中的模型项是“List”类型的,但是这个字典需要一个类型为“PagedList.IPagedList”的模型项`1

The model item passed into the dictionary is of type 'List`, but this dictionary requires a model item of type 'PagedList.IPagedList`1

当我 运行 我的观点时,我得到这个错误,我知道错误是什么,我知道之前问过这个问题,所以请不要让我失望让我解释 :) 我尝试创建新的 viewModel,然后将我的 viewModel 包装到 PagedList.IPagedList,但是当我这样做时,我无法访问我的属性,然后我调试并发现我应该将我的 ViewModel (RMAHistory) 的类型转换为 PagedList.IPagedList 或者我的 ViewModel 如何接受 PagedList.IPagedList,但老实说我不知道​​如何 :) :)

谁能给我指出正确的方向:)
提前致谢:)

错误: 传入字典的模型项的类型为 System.Collections.Generic.List1[ModelNameSpace.Models.RMAHistory]', but this dictionary requires a model item of type 'PagedList.IPagedList1[ModelNameSpace.Models.RMAHistory].

控制器:

public ActionResult RMAList(string searchingrma, int? pageNumber) 
    {

        List<RMAHistory> query = db.RMAStatus.Join(db.RMA_History, u => u.ID, y => y.StatusID, (u, y) => new { u, y }).
        Where(x => x.y.Ordrenummer.Contains(searchingrma) && x.y.Fakturnummer.Contains(searchingrma) || searchingrma == null).
        Select(t => new RMAHistory
        {

            OrdreDato = t.y.OrdreDato,
            AntalRMA = t.y.AntalRMA


        }).OrderBy(t => t.OrdreDato).ToPagedList(pageNumber ?? 1, 5).ToList();


        return View(query);




    }


查看:

@model IPagedList<ModelNameSpace.Models.RMAHistory>
@using PagedList;
@using PagedList.Mvc;

<table>

<tbody>

foreach (var rma in Model)
{
<tr>

<td class="tdft">@rma.OrdreDato.ToString("dd/MM/yyy")</td>
<td class="tdft">@rma.AntalRMA</td>

 }

</tr>
}

</tbody>


</table>

 @Html.PagedListPager(Model, pageNumber => Url.Action("RMAList", new
                        {
                            pageNumber,

                            searching = Request.QueryString["searchingrma"]

                        }))


视图模型:

public class RMAHistory
{
    public int? Id { get; set; }
    public DateTime OrdreDato { get; set; }
    public string AntalRMA { get; set; }

}

错误消息是不言自明的。您的操作方法应该 return IPagedList<ModelNameSpace.Models.RMAHistory> 而您正在 returning List<RMAHistory>.

因此,您的代码将是:

 public ActionResult RMAList(string searchingrma, int? pageNumber) 
        {

            var query = db.RMAStatus.Join(db.RMA_History, u => u.ID, y => y.StatusID, (u, y) => new { u, y }).
            Where(x => x.y.Ordrenummer.Contains(searchingrma) && x.y.Fakturnummer.Contains(searchingrma) || searchingrma == null).
            Select(t => new RMAHistory
            {

                OrdreDato = t.y.OrdreDato,
                AntalRMA = t.y.AntalRMA


            }).OrderBy(t => t.OrdreDato).ToPagedList(pageNumber ?? 1, 5);


            return View(query);
        }