OK, This is starting to get mildly irritating. I tried to implement Twitter style paging using ASP.NET MVC and JQuery. My problem is that when not using Request.IsAjaxRequest() (for users with javascript turned off) it works fine, obviously posting back the whole page. When I run the code for Request.IsAjaxRequest(), it skips entries, and does not return result in order. This is the code I have:
public ActionResult Index(int? startRow)
{
StatusUpdatesRepository statusUpdatesRepository = new StatusUpdatesRepository();
if (!startRow.HasValue)
startRow = Globals.Settings.StatusUpdatesSection.StatusUpdateCount;//5 Default starting row
//Retrieve the first page with a page size of entryCount
int totalItems;
if (Request.IsAjaxRequest())
{
IEnumerable<StatusUpdate> PagedEntries
= statusUpdatesRepository.GetLastStatusUpdates(startRow.Value,Globals.Settings.StatusUpdatesSection.StatusUpdateCount, out totalItems);
if (startRow < totalItems)
AddMoreUrlToViewData(startRow.Value);
return View("StatusUpdates", PagedEntries);
}
//Retrieve the first page with a page size of global setting
// First run skip 0 take 5
IEnumerable<StatusUpdate> entries
= statusUpdatesRepository.GetLastStatusUpdates(0,startRow.Value, out totalItems);
if (startRow < totalItems)
AddMoreUrlToViewData(startRow.Value);
return View(entries);
}
private void AddMoreUrlToViewData(int entryCount)
{
ViewData["moreUrl"] = Url.Action("Index", "Home", new { startRow = entryCount + Globals.Settings.StatusUpdatesSection.StatusUpdateCount });
}
My GetLastStatusUpdates function:
public IQueryable<StatusUpdate> GetLastStatusUpdates(int startRowIndex, int maximumRows,out int statusUpdatesCount )
{
statusUpdatesCount = db.StatusUpdates.Count();
return db.StatusUpdates
.Skip(startRowIndex)
.Take(maximumRows)
.OrderByDescending(s => s.AddedDate);
}
Really fresh out out of ideas as to why this is not working properly when responding to a Request.IsAjaxRequest(), ie when I turn off javascript in the browser, the code works perfectly, except I don't want to repost the whole page?