Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7941385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:39:20+00:00 2026-06-03T23:39:20+00:00

I currently have pagination working in my MVC 3 project using the PagedList library

  • 0

I currently have pagination working in my MVC 3 project using the PagedList library (https://github.com/TroyGoode/PagedList).

I would like to convert this code to update the page using ajax with the new results rather then refreshing the whole page. I’m not really sure how to go about that. Im rather new to MVC coming from Webforms. Any help would be greatly appreciated!

Heres my code:

Home Controller:

//#####################################
// ActionResult = Retrieve Comments
//#####################################
[ChildActionOnly]
public ActionResult _Comments(int ProductID, int? Page)
{
    //Perform the Database Query.
    try
    {
        //SQL Query - Get * records
        var Model = from r in DB.Comments where r.ProductID == ProductID select r;

        //Page number passed in via url. Default to 1 if not specified.
        var PageNumber = Page ?? 1;

        //Grab 6 results from the result set.
        var Results = Model.ToPagedList(PageNumber, 6);

        //Store Paged Result set in ViewBag for Paging.
        ViewBag.Results = Results;

        //Store in ViewBag for display (Page 1 of 43)
        ViewBag.PageNumber = PageNumber;

        //Get Total Pages: Divide Total Records by 6 Records per page.
        ViewBag.PageCount = Model.Count() / 6 + 1; 

        //Return Records to my view.
        return PartialView(Results);
    }
    //There was an error.
    catch
    {
        //ViewBag.ErrorMessage = ex;
        return PartialView("Error");
    }
}

PartialView: _Comments

@model IEnumerable<DH.Models.Comment>

@using PagedList.Mvc;
@using PagedList;

@{  
    //No Comments Yet
    if (@Model.Count() == 0)
    {
        <div id="CommentStatus">Be the first to comment on this product!</div>
    }
    //There are comments!
    else
    {
        foreach (var item in Model)
        {   
             //html for writing out the comments...
        }
    }
}

<div>Page @ViewBag.PageNumber of @ViewBag.PageCount</div>

@Html.PagedListPager((IPagedList)ViewBag.Results, Page => Url.Action("Index", new { Page = Page }), new PagedListRenderOptions { LinkToPreviousPageFormat = "< Prev", LinkToNextPageFormat = "Next >", LinkToLastPageFormat = "&Uacute;ltima >>" })

Model

namespace DH.Models
{
    public class Comment
    {  
        public int CommentID { get; set; }

        public int ProductID { get; set; }

        public string Author { get; set; }

        public string Message { get; set; }

        public DateTime MessageDate { get; set; }

        public int ThumbsUp { get; set; }

        public int ThumbsDown { get; set; }

        public string IP { get; set; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:39:21+00:00Added an answer on June 3, 2026 at 11:39 pm

    I’m the creator of the PagedList nuget package.

    There is an example of doing Ajax pagination (as well as infinite scrolling) in the project’s git repo:

    https://github.com/TroyGoode/PagedList/tree/master/src/PagedList.Mvc4.Example

    Controller:
    https://github.com/TroyGoode/PagedList/blob/master/src/PagedList.Mvc4.Example/Controllers/AjaxController.cs

    View:
    https://github.com/TroyGoode/PagedList/blob/master/src/PagedList.Mvc4.Example/Views/Ajax/Index.cshtml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following https://github.com/amatsuda/kaminari_example/commits/ajax . I'm using kaminari 0.12.4. (I had check with 0.13.0 and
i have pagination links like 1,2,3,4...am trying to change appearance of current page using
I currently have pagination functionality that displays the total page count, but I was
Currently have password protection on my main and sub directories, however I'd like to
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have a UINavigationController based application that works just fine. I'd like to
I'm currently working on a project with a very tight budget, and one of
SCENARIO: I have a Pictures table that contains hundreds of photos. I'm currently using
I have a pagination that needs to look like that: a busy cat http://img338.imageshack.us/img338/3180/pagination.jpg
I currently have created a pagination JavaScript class that will automatically paginate comments when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.