Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 传入字典的模型项的类型为';列表“”,但此词典需要类型为';PagedList.IPagedList`1_C#_Asp.net Mvc_Pagedlist - Fatal编程技术网

C# 传入字典的模型项的类型为';列表“”,但此词典需要类型为';PagedList.IPagedList`1

C# 传入字典的模型项的类型为';列表“”,但此词典需要类型为';PagedList.IPagedList`1,c#,asp.net-mvc,pagedlist,C#,Asp.net Mvc,Pagedlist,当我运行我的视图时,我得到了这个错误,我知道错误是关于什么的,我知道就像以前问的这个问题一样,所以请不要投票否决我,让我解释一下:) 我尝试创建新的viewModel,然后将我的viewModel包装到PagedList.IPagedList中,但当我这样做时,我无法访问我的属性,于是我调试并发现我应该将我的viewModel类型(RMAHistory)转换为PagedList.IPagedList或我的viewModel如何接受PagedList.IPagedList,但老实说,我不知道如何:

当我运行我的视图时,我得到了这个错误,我知道错误是关于什么的,我知道就像以前问的这个问题一样,所以请不要投票否决我,让我解释一下:) 我尝试创建新的viewModel,然后将我的viewModel包装到PagedList.IPagedList中,但当我这样做时,我无法访问我的属性,于是我调试并发现我应该将我的viewModel类型(RMAHistory)转换为PagedList.IPagedList或我的viewModel如何接受PagedList.IPagedList,但老实说,我不知道如何:)

谁能给我指一下正确的方向:)
提前感谢:)

错误: 传递到字典的模型项的类型为System.Collections.Generic.List
1[ModelNameSpace.Models.RMAHistory]”,但此字典需要类型为“PagedList.IPagedList
1[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);




    }

错误消息是不言自明的。您的操作方法应该返回
IPagedList
,您正在返回
List

因此,您的代码是:

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

列表查询
更改为
IPagedList
,并从列表中删除
.ToList()
query@StephenMuecke谢谢,谢谢,谢谢,你的真棒:)如果你能发布你的anwser,我会标记为正确的anwser,再次感谢您,我花了很多时间在这上面,它很有效:)Tanmay已经添加了:)很可能是更好的副本。是的,我知道,我只是不知道如何将viewmodel上的类型转换为IPagedList,直到@StephenMuecke帮助我:)无论如何,谢谢您的回答,它也是正确的:)
public class RMAHistory
{
    public int? Id { get; set; }
    public DateTime OrdreDato { get; set; }
    public string AntalRMA { get; set; }

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