2016-08-03 31 views
1

服務器端分頁我正在使用PageList。我看到:https://www.youtube.com/watch?v=5omEuuIIFcgMVC實體框架服務器端分頁PageList

我正在使用ViewModel。我遵循「丹尼斯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的兩個表?

回答

0

我解決了這個問題。在地點列表<>在視圖模型我現在..

public class DashboardViewModel 
    { 
     public PagedList<SummaryViewModel> SummaryRestricted { get; set; } 

     public PagedList<SummaryViewModel> SummaryUnrestricted { get; set; } 

    } 

它的正常工作更換。