本文介绍了如何使用和显示 PagedResultDto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

首先,引入 IPagedResultRequest 作为输入:

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

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

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

MaxResultCount 有一个 默认值 10.

这篇关于如何使用和显示 PagedResultDto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:14