我正在一个 ASP.NET MVC3 应用程序上提取分页数据集,该应用程序使用 JQuery 通过 $ajax 调用获取用于无限滚动分页的数据。后端是 Azure SQL 数据库。这是代码:
[Authorize]
[OutputCache(Duration=0,NoStore=true)]
public PartialViewResult Search(int page = 1)
{
int batch = 10;
int fromRecord = 1;
int toRecord = batch;
if (page != 1)
{
//note these are correctly passed and set
toRecord = (batch * page);
fromRecord = (toRecord - (batch - 1));
}
IQueryable<TheTable> query;
query = context.TheTable.Where(m => m.Username==HttpContext.User.Identity.Name)
.OrderByDescending(d => d.CreatedOn)
.Skip(fromRecord).Take(toRecord);
//this should always be the batch size (10)
//but seems to concatenate the previous results ???
int count = query.ToList().Count();
//results
//call #1, count = 10
//call #2, count = 20
//call #3, count = 30
//etc...
PartialViewResult newPartialView = PartialView("Dashboard/_DataList", query.ToList());
return newPartialView;
}
从 Jquery $ajax 每次调用返回的数据在每次后续调用中继续增长,而不是每次调用仅返回 10 条记录。因此,返回的结果也包含所有早期调用数据。此外,我还在 $ajax 调用中添加了 'cache=false'。关于这里出了什么问题的任何想法?