Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda