Error while paging using Pagedlist with List<Dinamyc>

Asked

Viewed 89 times

0

I’m trying to make a pagination of a Webgrid using Pagedlist but there is conversion error:

Additional information: Cannot convert type implicitly 'Pagedlist.Pagedlist' in 'System.Collections.Generic.List'

I don’t know if it occurs due to variable dns be the type List<dynamic> as shown below:

inserir a descrição da imagem aqui

ViewBag.Columns = columns;                    
                var dns = new List<dynamic>();
                dns = Util.DataTableParaDynamic.ConverterDtParaList(dt);
                int paginaTamanho = 15;
                int paginaNumero = (page);
                ViewBag.Total = dns.ToPagedList(paginaNumero, paginaTamanho); 

It is not necessary to use Pagedlist I can use any other means that make the pagination and work under these conditions.

1 answer

0

No need to use the PagedList, just use the Skip and the Take that works perfectly:

dns = Util.DataTableParaDynamic.ConverterDtParaList(dt);
                if (dns.Count > pageNumber)
                {
                    ViewBag.Total = dns.Skip((pageSize - 1) * pageNumber)
                                        .Take(pageSize)
                                        .ToList();
                }else
                {
                    ViewBag.Total = dns;
                }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.