C# MVC实体框架服务器端分页页面列表
对于服务器端分页,我使用PageList。我看到: 我正在使用ViewModel。我遵循“Dennis R”给出的步骤 但我有不同的视图模型: 我的实体类C# MVC实体框架服务器端分页页面列表,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,对于服务器端分页,我使用PageList。我看到: 我正在使用ViewModel。我遵循“Dennis R”给出的步骤 但我有不同的视图模型: 我的实体类 public class Summary { } viewmodel是: public class SummaryViewModel { ... .... } public class DashboardViewModel { public List<
public class Summary
{
}
viewmodel是:
public class SummaryViewModel
{
...
....
}
public class DashboardViewModel
{
public List<SummaryViewModel> SummaryRestricted { get; set; }
public List<SummaryViewModel> SummaryUnrestricted { get; set; }
}
公共类摘要视图模型
{
...
....
}
公共类仪表板视图模型
{
公共列表摘要受限{get;set;}
公共列表摘要不受限制{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;
}
公共操作结果显示(int page=1,int pagesize=4)
{
var entitySummaries=_dbContext.Summaries.ToList();
var vm=MapEntityToViewModel(entitySummaries);
//返回视图(vm);
//返回视图(vm.FundsUnrestricted.ToPagedList(page,pagesize))????
}
仪表板视图模型映射实体到视图模型(列出资金)
{
DashboardViewModel DashboardViewModel=新的DashboardViewModel();
List unRestricted=资金。其中(x=>xxx).ToList();
列表受限=基金。其中(x=>xx).ToList();
dashboardViewModel.SummaryUnrestricted=无限制。选择(x=>new SummaryViewModel(x)).ToList();
dashboardViewModel.SummaryRestricted=restricted.Select(x=>new SummaryViewModel(x)).ToList();
返回仪表板视图模型;
}
我的看法是:
@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>
@model PagedList.IPagedList
@使用PagedList.Mvc;
@使用页面列表;
@foreach(模型中的ViewModels.SummaryViewModel项。SummaryRestricted)
{
}
@foreach(Model.summary中的ViewModels.Summary ViewModel项不受限制)
{
}
我的视图必须在同一页上显示受限摘要和非受限摘要的表格。有谁能帮助我如何使用pageList在两个表上应用分页 我解决了这个问题。代替视图模型中的列表,我将其替换为
public class DashboardViewModel
{
public PagedList<SummaryViewModel> SummaryRestricted { get; set; }
public PagedList<SummaryViewModel> SummaryUnrestricted { get; set; }
}
公共类仪表板视图模型
{
公共页面列表摘要受限{get;set;}
公共页面列表摘要不受限制{get;set;}
}
现在一切正常。我解决了这个问题。代替视图模型中的列表,我将其替换为
public class DashboardViewModel
{
public PagedList<SummaryViewModel> SummaryRestricted { get; set; }
public PagedList<SummaryViewModel> SummaryUnrestricted { get; set; }
}
公共类仪表板视图模型
{
公共页面列表摘要受限{get;set;}
公共页面列表摘要不受限制{get;set;}
}
现在很好用