Does anyone know how to implement a paging or would I have an example using this architecture link I would like to use Linq's Skip () and Take ():
As was done in this example MVC asp.net page
But I'm having an error:
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);
}