1
Does anyone know how to implement a pagination or would have an example using this architecture https://github.com/cleytonferrari/PadraoDeRepositorio/tree/master/TISelvagem I would like to use the Skip() and Take() from Latin:
As was done in this example MVC Asp.net paging
but I’m having a mistake:
public IEnumerable<Cliente> ListarPagina(int paginaAtual, int itensPorPagina)
{
return contexto.Cliente.Skip((paginaAtual - 1) * itensPorPagina).Take(itensPorPagina).ToList();
}
public class ListaPaginada<T>
{
public int TotalItens { get; private set; }
public int ItensPorPagina { get; private set; }
public int PaginaAtual { get; private set; }
public int TotalPaginas
{
get { return Math.Ceil(TotalItens / ItensPorPagina); }
}
public List<T> Itens { get; private set; }
public ListaPaginada(List<T> itens, int totalItens, int itensPorPagina, int paginaAtual)
{
this.Itens = itens;
this.TotalItens = totalItens;
this.ItensPorPagina = itensPorPagina;
this.PaginaAtual = paginaAtual;
}
}
public ListaPaginada<Cliente> ListarPagina(int paginaAtual, int itensPorPagina)
{
var clientes = contexto.Cliente;
var totalClientes = cliente.Count();
var clientesDaPagina = cliente.Skip((paginaAtual - 1) * itensPorPagina).Take(itensPorPagina).ToList();
return new ListaPaginada<Cliente> (clientesDaPagina, totalClientes, itensPorPagina, paginaAtual);
}
This I do not know, I use this one, it serves me 100%, I have 400 thousand records. https://www.nuget.org/packages/PagedList.Mvc/
– Ricardo
I would like to learn to do is not to use ready-made things, not that I am against each use what you think best, but I would like to learn to do
– Harry
So put what you’ve done so we can debate the problems and doubts. The question is quite vague, actually not hard to do no, but everything will depend on the technologies you chose
– Ricardo
All right, there you go!
– Harry