问题
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