How to use and display PagedResultDto

六眼飞鱼酱① 提交于 2019-12-06 16:09:17

First, take in IPagedResultRequest as input:

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

Then create your own links to pass in SkipCount, e.g. GetAll?SkipCount=10 for page 2.

MaxResultCount has a default value of 10.

You can calculate it according to the result of GetAll(). You request how many records you want. Let's say 10 (default value). It returns TotalCount and Items (=records). Let's say TotalCount = 95. Divide 95/10 = 9.5 ~=> 10 pages. Show 10 links. While 9 pages will show 10 records, last page will have 5 records. That

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!