V
V
VanilaSpirit2020-07-19 00:23:19
ASP.NET
VanilaSpirit, 2020-07-19 00:23:19

ASP.NET Core how to convert pagination(PagedList) to ajax?

index.cshtml:

@model X.PagedList.IPagedList<Employees.Models.Employee>
@using X.PagedList.Mvc.Core;

<table class="table" id="Table">
    <thead>
        <tr>
            <th>Имя</th>
            <th>Возраст</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Name</td>
                <td>@item.Age</td>
            </tr>
        }
    </tbody>
</table>

<div class="pagination">
    Страница @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) из @Model.PageCount

    @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
</div>


Controller:
public IActionResult Index(int? page)
        {
            int pageSize = 3;
            int pageNumber = (page ?? 1);
            return View(employeeRepository.GetEmployees().ToPagedList(pageNumber, pageSize));
        }


The code works and switches pages, but it is required to do the switching without reloading the page, i.e. ajax

Maybe someone will guide you on the right path?
Will PartialView cope with this if we move the pagination with the table there?

I will be if you "chew" how this can be done.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question