Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
Refresh Table without refreshing page with html helper PagedListPager

I have the following line of code which uses html helper's PagedListPager:

@Html.PagedListPager(Model.kyc_paged_list, page => Url.Action("ClientDetails", new { id = ViewBag.ID, kyc_page = page, transaction_page = Model.transaction_page, active = "kyc" }))

When clicking on the the pager the entire page reloads. But I only want the table with id="kyc-history" to refresh.

I know how to reload the table using a JavaScript function but I don't know how to call it from the PagedListPager. Any ideas how I can call it? Let's say that the JS function is called reloadTable()

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was having the same problem and this article (done by Anders Lybecker) helped me out and now everything working! It's very clear with steps, But make sure to make backup before starting!

Take a look: AJAX paging for ASP.NET MVC sites

In summary you make 2 Action Results in your Controler with 2 Views 1 for your page (in my case it's Index View) the other for the List that contain the PagedListPager control (List View). And put the list View inside the Index View. And write the JQuery code for the PagedListPager in the Index View.

You can read the article for the details!

And this is my code with a little extra things I noticed to help you more:

The List View:

@model IPagedList<StudentRegSys.Models.Student>
@{
    Layout = null;
}

@using PagedList.Mvc;
@using PagedList;

<link href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,600,700" rel="stylesheet">
@Styles.Render("~/template/css")

<div class="container">
    <div class="row">

          <!-- The List Code-->

        <div class="pagination-control">
            @Html.PagedListPager(Model, i => Url.Action("List", "Home", new { i, search = Request.QueryString["search"] }))
        </div>
    </div>
</div>
@Scripts.Render("~/template/js")

Note: Make sure to make Layout = null; and put the Styles Links & the Scripts manual in this View to avoid design issues.

In the Controller: (it's Home Controller in my case)

// GET: /Home/Index
public ViewResult Index()
{
    return View();
}

// GET: /Home/List
public ActionResult List(int? i, string search = "")
{
    try
    {
        var students = _context.Student.Include(s => s.Major)
            .OrderBy(s => s.Name)
            .Where(s => s.Name.Contains(search) || s.Major.Name.Contains(search) ||
            s.Address.Contains(search) || s.Phone.Contains(search))
            .ToList().ToPagedList(i ?? 1, 8);


        return View(students);
    }
    catch (Exception)
    {
        return HttpNotFound();
    }
}

The Index View:

@{
    ViewBag.title = "Home";
}

<section id="intro">
    <!-- Some Code -->
</section>

<section id="maincontent">

    @Html.Action("List") <!-- to call the List view --> 

</section>

    <script>
    $(document).ready(function () {
        $(document).on("click", ".pagination-control a[href]", function () {
            $.ajax({
                url: $(this).attr("href"),
                type: 'GET',
                cache: false,
                success: function (result) {
                    $('#maincontent').html(result);
                }
            });
            return false;
        });
    });
    </script>

Note: Make sure to put the html(result) in the root container of the list in my case was <section id="maincontent">.

Hope this help you out :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!