C
C#2y ago
XANDRO

❔ How to create pagination in ASP NET MVC?

I tried PagedList but that didn't work for me, any suggestions?
6 Replies
lycian
lycian2y ago
What didn't work with PagedList? That's the easiest way I know of if you're using EF
Angius
Angius2y ago
.Skip().Take() for offset pagination
XANDRO
XANDROOP2y ago
The problem is PagedList doesn't work in ASP NET CORE
Angius
Angius2y ago
var items = await _context.Things
.OrderBy(t => t.Id)
.Skip((page - 1) * perPage)
.Take(perPage)
.ToListAsync();
var items = await _context.Things
.OrderBy(t => t.Id)
.Skip((page - 1) * perPage)
.Take(perPage)
.ToListAsync();
Use a
public sealed record PaginationResult<T>(
IEnumerable<T> Items,
int Page,
int PerPage,
int TotalItems
)
public sealed record PaginationResult<T>(
IEnumerable<T> Items,
int Page,
int PerPage,
int TotalItems
)
kind of a thing to represent the pagination result
jcotton42
jcotton422y ago
it shouldn't be that hard to implement whatever endpoint gets the data just needs the paging info in its parameters an offset if you're using offset pagination or an "after" if you're using keyset pagination if they're blank, you're starting from the beginning
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server