我需要使用多列过滤和分页制作自定义数据网格视图。所以我做了一个视图模型winch将封装三个类
过滤工作正常但不分页:(。当我按下分页链接时松开视图模型"似乎我还需要提交搜索表单" 任何人都可以显示我在按下链接时如何提交表单。 这是我的观点
@model TestFilteringAndPagination.ViewModels.CarViewModel
@{
ViewBag.Title = "Home Page";
}
@*Search form*@
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "frm" }))
{
@Html.HiddenFor(m => Model.Pager.CurrentPage)
@Html.HiddenFor(m => Model.Pager.PageSize)
@Html.HiddenFor(m => Model.Pager.EndPage)
@Html.HiddenFor(m => m.Pager.StartPage)
<div class="form-inline">
<div class="form-group">
<label>Car No</label>
@Html.EditorFor(x => x.Filter.CarNumber, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Line name</label>
@Html.EditorFor(x => x.Filter.LineName, new { @class = "form-control" })
</div>
<button type="submit" class="btn btn-default">Search</button>
</div>
<ul class="pagination">
@for (var page = Model.Pager.StartPage; page <= Model.Pager.EndPage; page++)
{
<li class="@(page == Model.Pager.CurrentPage ? "active" : "")">
<a href="#">@page</a>
</li>
}
</ul>
}
@*Data grid*@
<table class="table">
<thead>
<tr>
<th>
Car number
</th>
<th>
Car Line
</th>
</tr>
</thead>
<tbody>
@foreach (var car in Model.Cars)
{
<tr>
<td>
@Html.DisplayFor(x => car.CarNumber)
</td>
<td>
@Html.DisplayFor(x => car.LineName)
</td>
</tr>
}
</tbody>
</table>
答案 0 :(得分:0)
您可以安装PagedList.MVC NuGet Package,有关如何准确创建所需内容的详细信息,请参阅此帖子。
Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application