【发布时间】:2019-02-19 05:28:50
【问题描述】:
我搜索了,但并没有真正找到关于如何在 ASP.NET WebAPI Core 2.1 应用程序中实现分页逻辑的文章...
我有以下
[Route("api/[controller]")]
[ApiController]
[EnableCors("AllowMyOrigin")]
public class EntriesController : ControllerBase
{
private readonly EntriesContext _context;
public EntriesController(EntriesContext context) {
_context = context;
if (_context.Entries.Count() == 0) {
_context.Entries.Add(new Entry { From = "default", To = "default" });
_context.SaveChanges();
}
}
[HttpGet]
public ActionResult<List<Entry>> GetAll() {
return _context.Entries.ToList();
}
[HttpGet("{id}", Name = "GetEntry")]
public ActionResult<Entry> GetById(long id) {
var item = _context.Entries.Find(id);
if (item == null) { return NotFound(); }
return item;
}
现在,我希望使用新参数 page 和 pageSize 对我的条目进行分页。说
/api/entries?pageSize=3&page=2
我应该通过添加一些 http 参数来使用 GetAll() 方法,还是创建一个新方法?没有pageSize,使用page没有多大意义,我该如何管理?
【问题讨论】:
标签: asp.net-core pagination asp.net-core-webapi asp.net-core-2.1