如何使用和显示PagedResultDto

时间:2017-12-19 02:52:14

标签: aspnetboilerplate

使用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>>()
        };
    }

2 个答案:

答案 0 :(得分:4)

首先,输入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,例如第2页GetAll?SkipCount=10

MaxResultCount的{​​{3}} 10

答案 1 :(得分:0)

您可以根据GetAll()的结果来计算它。 您可以请求所需的记录数。让我们说10(默认值)。 它返回TotalCount和Items(=记录)。让我们说TotalCount = 95.除以95/10 = 9.5~ =&gt; 10页。显示10个链接。虽然9页将显示10条记录,但最后一页将有5条记录。这