Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
4096 Russian (Kazakhstan) русский (Казахстан)
4096 Russian (Kyrgyzstan) русский (Киргизия)
2073 Russian (Moldova) русский (Молдова)
1049 Russian (Russia) русский (Россия)
4096 Russian (Ukraine) русский (Украина)
4096 Rwa Kiruwa
4096 Rwa (Tanzania) Kiruwa (Tanzania)
4096 Saho Saho
4096 Saho (Eritrea) Saho (Eretria)
133 Sakha Саха
1157 Sakha (Russia) Саха (Россия)
4096 Samburu Kisampur
4096 Samburu (Kenya) Kisampur (Kenya)
28731 Sami (Inari) anarâškielâ
31803 Sami (Lule) julevusámegiella
29755 Sami (Skolt) sää´mǩiõll
30779 Sami (Southern) åarjelsaemiengïele
9275 Sami, Inari (Finland) anarâškielâ (Suomâ)
4155 Sami, Lule (Norway) julevusámegiella (Vuodna)
5179 Sami, Lule (Sweden) julevusámegiella (Svierik)
3131 Sami, Northern (Finland) davvisámegiella (Suopma)
1083 Sami, Northern (Norway) davvisámegiella (Norga)
2107 Sami, Northern (Sweden) davvisámegiella (Ruoŧŧa)
8251 Sami, Skolt (Finland) sää´mǩiõll (Lää´ddjânnam)
6203 Sami, Southern (Norway) åarjelsaemiengïele (Nöörje)

Setup for ajax

  • Create a div element that will handle the updated the content
    <div class="items"></div>
  • Create a partial view to render in the target area e.g. PagingItemsPartial.cshtml. The partial view model is the same as the page model in out sample PagingAjaxModel.
  • Put the paging taghelper in the partial, currently it supports only "replace" mode for ajax, thats why we have to keep the paging inside the partial, so it will refresh with the partial data accordingly.
  • Use ajax-... attributes to add ajax support to the PagingTagHelper.
  • In the backend, create the relevant handler that will return the partial view via ajax.
  • Add reference to ajax in the Scripts section:
    <script src="https://cdn.jsdelivr.net/npm/jquery-ajax-unobtrusive@3.2.6/dist/jquery.unobtrusive-ajax.min.js"></script>

Sample partial view with Paging control included

            
@model PagingAjaxModel

<table class="table table-striped">
    <thead>
        <tr>
            <th>LCID</th>
            <th>English Name</th>
            <th>Native Name</th>
        </tr>
    </thead>
    <tbody>
        @if (Model.TotalRecords == 0)
        {
            <tr>
                <td colspan="3">No records!</td>
            </tr>
        }
        else
        {
            foreach (var c in Model.CulturesList)
            {
                <tr>
                    <td>@c.LCID</td>
                    <td>@c.EnglishName</td>
                    <td>@c.NativeName</td>
                </tr>
            }
        }
    </tbody>
    <tfoot>
        <tr>
            <td colspan="3">
                <paging page-no="Model.P"
                        page-size="Model.S"
                        total-records="Model.TotalRecords"
                        ajax="true"
                        ajax-url="?handler=AjaxPaging"
                        ajax-update="#items"
                        ajax-loading="#loading-spinner"></paging>
            </td>
        </tr>
    </tfoot>
</table>