如何使用和显示PagedResultDto

How to use and display PagedResultDto

使用 ASPNet Boilerplate,并使用以下代码返回 pagedResultSetDto,如何显示页面链接?

 public PagedResultDto<ArticleDto> GetAll()
    {
        var articleCount = articleRepository.Count();

        var t = articleRepository.GetAllIncluding(x => x.articleImage).Include(x => x.Category).Where(
                x => x.PublishFrom <= DateTime.Now &&
                x.PublishTo >= DateTime.Now &&
                 x.Status == PostStatus.Published &&
                 x.IsDeleted == false
                ).OrderByDescending(x=> x.PublishFrom).ToList();

        return new PagedResultDto<ArticleDto>
        {
            TotalCount = articleCount,
            Items = t.MapTo<List<ArticleDto>>()
        };
    }

首先,将IPagedResultRequest作为输入:

// using Abp.Linq.Extensions;

public PagedResultDto<ArticleDto> GetAll(PagedResultRequestDto input)
{
    var articleCount = articleRepository.Count();

    var t = articleRepository
            .GetAllIncluding(x => x.articleImage)
            .Include(x => x.Category)
            .Where(x =>
                x.PublishFrom <= DateTime.Now &&
                x.PublishTo >= DateTime.Now &&
                x.Status == PostStatus.Published &&
                x.IsDeleted == false
            )
            .OrderByDescending(x => x.PublishFrom)
            .PageBy(input) // Page by SkipCount and MaxResultCount
            .ToList();

    return new PagedResultDto<ArticleDto>
    {
        TotalCount = articleCount,
        Items = t.MapTo<List<ArticleDto>>()
    };
}

然后创建您自己的链接以传入 SkipCount,例如GetAll?SkipCount=10 第 2 页。

MaxResultCountdefault value10

你可以根据GetAll()的结果来计算。 您请求您想要多少条记录。假设 10(默认值)。 它 returns TotalCount 和 Items(=records)。假设 TotalCount = 95。划分 95/10 = 9.5 ~=> 10 页。显示 10 个链接。 9 页将显示 10 条记录,而最后一页将显示 5 条记录。那