【问题标题】:MVC Entity Framework server side pagination PageListMVC Entity Framework 服务器端分页 PageList
【发布时间】: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


    【解决方案1】:

    我解决了。代替视图模型中的列表,我将其替换为..

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

    现在一切正常。

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2023-03-12
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2016-05-04
      相关资源
      最近更新 更多