1

for server side pagination i am using PageList. I saw: https://www.youtube.com/watch?v=5omEuuIIFcg

I am using ViewModel. I followed steps given by "Dennis R".

Using a PagedList with a ViewModel ASP.Net MVC

But i have different kind of view model:

My Entity Class

public class Summary
{

}

viewmodel is:

 public class SummaryViewModel
    {
     ...         
     ....
    }

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

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

    }

my Controller class:

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;           
        }

my view is:

@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>

my view has to display both the tables for restricted summaries and unrestricted summary on same page. can anyone help me how can i apply paging on both the tables using pageList?

Community
  • 1
  • 1
bansi
  • 99
  • 2
  • 12

1 Answers1

0

I solved that. in place of list<> in view model i replace it with..

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

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

    }

it's working fine now.

bansi
  • 99
  • 2
  • 12