using CoreWiki.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace CoreWiki.Pages; public class All : PageModel { private readonly ApplicationDbContext _context; [BindProperty(SupportsGet = true)] public int PageNumber { get; set; } = 1; [BindProperty(SupportsGet = true)] public int PageSize { get; set; } = 25; public IEnumerable
Articles { get; set; } public int TotalPages { get; set; } public All(ApplicationDbContext context) { _context = context; } public async Task OnGetAsync() { TotalPages = (int)Math.Ceiling(await _context.Articles.CountAsync() / (float)PageSize); if (PageNumber > TotalPages) PageNumber = 1; Articles = await _context.Articles .AsNoTracking() .OrderBy(a => a.PublishedDateTime) .Skip(PageSize * (PageNumber - 1)) .Take(PageSize) .ToArrayAsync(); return Page(); } }