我正在尝试将网格添加到我的 MVC 应用程序中的数据表中,但不断收到以下错误消息:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[AssociateTracker.Models.Associate]', but this dictionary requires a model item of type 'PagedList.IPagedList`1[AssociateTracker.Models.Associate]'.
看法:
@model PagedList.IPagedList<AssociateTracker.Models.Associate>
@{
ViewBag.Title = "ViewAll";
}
<h2>View all</h2>
<table>
<tr>
<th>First name</th>
<th>@Html.ActionLink("Last Name", "ViewAll", new { sortOrder=ViewBag.NameSortParm, currentFilter=ViewBag.CurrentFilter })</th>
<th>Email address</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.FirstName</td>
<td>@item.LastName</td>
<td>@item.Email</td>
<td>
@Html.ActionLink("Details", "Details", new { id = item.AssociateId }) |
@Html.ActionLink("Edit", "Edit", new { id = item.AssociateId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.AssociateId })
</td>
</tr>
}
</table>
<div>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<", "ViewAll", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter })
@Html.Raw(" ");
@Html.ActionLink("< Prev", "ViewAll", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter })
}
else
{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.HasNextPage)
{
@Html.ActionLink("Next >", "ViewAll", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter })
@Html.Raw(" ");
@Html.ActionLink(">>", "ViewAll", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter })
}
else
{
@:Next >
@Html.Raw(" ")
@:>>
}
</div>
我检查了 Microsoft 的Contosos University示例,但没有发现任何差异。其他人可以看到问题可能是什么吗?