我的问题是这个问题的延续:
在开始的代码块中:
<div>Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
我已经在我的项目中实现了这一点,它非常适合创建页面和适当的导航链接。但它并没有从数据库中提取我的实际列表;只是页面链接。
这是我之前在 Index.cshtml 文件中的内容:
@model IEnumerable<PtoTracker.Employee>
@{
ViewBag.Title = "Employees";
}
<h2>Employees</h2>
<p>
@Html.ActionLink("Add New Employee", "Create")
</p>
<table>
<tr>
<th></th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmployeeName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.EmployeeID }) |
@Html.ActionLink("Details", "Details", new { id=item.EmployeeID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.EmployeeID })
</td>
</tr>
}
</table>
上面的代码效果很好,但这只是一长串员工。如何将上述代码与此处显示的分页部分合并:
<div>Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<", "Index", new { page = 1, sortOrder = ViewBag.CurrentSort });
@Html.Raw(" ");
@Html.ActionLink("< Prev", "Index", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort });
}
else
{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.HasNextPage)
{
@Html.ActionLink("Next >", "Index", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort });
@Html.Raw(" ");
@Html.ActionLink(">>", "Index", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort });
}
else
{
@:Next >
@Html.Raw(" ");
@:>>
}
</div>