How to use and display PagedResultDto

六月ゝ 毕业季﹏ 提交于 2019-12-08 05:42:06

问题


Using ASPNet Boilerplate, and returning a pagedResultSetDto with the below code, how do I display the page links?

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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/47879378/how-to-use-and-display-pagedresultdto

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