ASP.NET MVC pagination problem????

Posted by MD_Oppenheimer on Stack Overflow See other posts from Stack Overflow or by MD_Oppenheimer
Published on 2010-03-17T16:48:14Z Indexed on 2010/03/17 16:51 UTC
Read the original article Hit count: 582

Filed under:
|
|
|

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 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 of javascript in the browser, the code works perfectly, except I don't want to repost the whole page????

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc