0
我拉一個ASP.NET MVC3應用程序的分頁數據集,它使用JQuery通過$ ajax調用獲取無數滾動分頁的數據。後端是一個Azure SQL數據庫。下面是代碼:LINQ,跳過並採取對抗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的$阿賈克斯每個調用返回的持續增長上的每個後續調用而然後返回每次通話只有10條記錄。所以結果返回也包含所有早期的調用數據。另外,我還爲$ ajax調用添加了'cache = false'。關於這裏出了什麼問題的任何想法?
感謝理查德!我感謝您的幫助。 – 2013-03-18 19:27:03