Page consultation with Linq

0

I have the following driver:

I need at the end to send you the invoices but paginated but to 20 ...

    public ActionResult Index()
    {                   

        //se trae la informacion de la base de datos y/o modelo
        var facturas = db.VwFacturasGeneralFull;         

        //por defecto el siguiente switch va ornedar por el sigueinte:
        var facturasOrdenadas = facturas.OrderBy(f => f.IDFactura).ToList();


      return View(facturasOrdenadas.ToList());
    }

I have tried it in various ways but I do not succeed.

    
asked by Jhon Castrillon 18.06.2017 в 03:06
source

2 answers

0

If what you need is to take a certain range of values from the list in your case the first 20 values you can use something like this:

 var listaADevolver =facturasOrdenadas.GetRange(0, 20);

I hope you find it useful.

    
answered by 19.06.2017 в 08:47
0

to perform the pagination you must use the methods Skip () and Take () as I show you in the following example

int numberOfObjectsPerPage = 20;
int pageNumber = 1;

var queryResultPage = queryResult
                          .Skip(numberOfObjectsPerPage * pageNumber)
                          .Take(numberOfObjectsPerPage);

I leave a link to an article (in English) that can be useful Return Or Skip Elements in a Sequence

    
answered by 19.06.2017 в 10:40