【发布时间】:2018-06-18 13:05:56
【问题描述】:
当我运行我的视图时,我得到了这个错误,我知道错误是关于什么的,我知道之前问过这个问题,所以请不要投票给我,让我解释一下 :) 我尝试创建新的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; }
}
【问题讨论】:
-
将
List<RMAHistory> query更改为IPagedList<RMAHistory>并从查询中删除.ToList() -
@StephenMuecke 谢谢谢谢谢谢,你太棒了:)
-
Tanmay 已经添加了 :)
-
stackoverflow.com/questions/19254055/… 可能是更好的副本。
标签: c# asp.net-mvc pagedlist