【发布时间】:2016-08-03 17:36:44
【问题描述】:
对于服务器端分页,我使用的是 PageList。我看到了:https://www.youtube.com/watch?v=5omEuuIIFcg
我正在使用 ViewModel。我遵循“Dennis R”给出的步骤。
Using a PagedList with a ViewModel ASP.Net MVC
但我有不同类型的视图模型:
我的实体类
public class Summary
{
}
视图模型是:
public class SummaryViewModel
{
...
....
}
public class DashboardViewModel
{
public List<SummaryViewModel> SummaryRestricted { get; set; }
public List<SummaryViewModel> SummaryUnrestricted { get; set; }
}
我的控制器类:
public ActionResult Display(int page = 1, int pagesize = 4)
{
var entitySummaries = _dbContext.Summaries.ToList();
var vm = MapEntityToViewModel(entitySummaries );
//return View(vm);
//return View(vm.FundsUnrestricted.ToPagedList(page, pagesize)); ????
}
DashboardViewModel MapEntityToViewModel(List<Summary> funds)
{
DashboardViewModel dashboardViewModel = new DashboardViewModel();
List<Summary> unRestricted = funds.Where(x => xxx).ToList() ;
List<Summary> restricted = funds.Where(x => xx).ToList();
dashboardViewModel.SummaryUnrestricted = unRestricted.Select(x => new SummaryViewModel(x)).ToList();
dashboardViewModel.SummaryRestricted = restricted.Select(x => new SummaryViewModel(x)).ToList();
return dashboardViewModel;
}
我的看法是:
@model PagedList.IPagedList<ViewModels.DashboardViewModel>
@using PagedList.Mvc;
@using PagedList;
<table id="Restricted" class="table table-bordered">
@foreach (ViewModels.SummaryViewModel item in Model.SummaryRestricted)
{
<tr> <tr>
}
</table>
<table id="UnRestricted" class="table table-bordered">
@foreach (ViewModels.SummaryViewModel item in Model.SummaryUnrestricted )
{
<tr> <tr>
}
</table>
我的视图必须在同一页面上同时显示受限摘要表和非受限摘要表。谁能帮助我如何使用 pageList 在两个表上应用分页?
【问题讨论】:
标签: c# asp.net-mvc entity-framework