Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
4096 French (Equatorial Guinea) français (Guinée équatoriale)
1036 French (France) français (France)
4096 French (French Guiana) français (Guyane française)
4096 French (French Polynesia) français (Polynésie française)
4096 French (Gabon) français (Gabon)
4096 French (Guadeloupe) français (Guadeloupe)
4096 French (Guinea) français (Guinée)
15372 French (Haiti) français (Haïti)
5132 French (Luxembourg) français (Luxembourg)
4096 French (Madagascar) français (Madagascar)
13324 French (Mali) français (Mali)
4096 French (Martinique) français (Martinique)
4096 French (Mauritania) français (Mauritanie)
4096 French (Mauritius) français (Maurice)
4096 French (Mayotte) français (Mayotte)
6156 French (Monaco) français (Monaco)
14348 French (Morocco) français (Maroc)
4096 French (New Caledonia) français (Nouvelle-Calédonie)
4096 French (Niger) français (Niger)
8204 French (Réunion) français (La Réunion)
4096 French (Rwanda) français (Rwanda)
4096 French (Saint Barthélemy) français (Saint-Barthélemy)
4096 French (Saint Martin) français (Saint-Martin)
4096 French (Saint Pierre and Miquelon) français (Saint-Pierre-et-Miquelon)
10252 French (Senegal) français (Sénégal)
4096 French (Seychelles) français (Seychelles)
4108 French (Switzerland) français (Suisse)
4096 French (Syria) français (Syrie)
4096 French (Togo) français (Togo)
4096 French (Tunisia) français (Tunisie)
4096 French (Vanuatu) français (Vanuatu)
4096 French (Wallis and Futuna) français (Wallis-et-Futuna)
9228 French Congo (DRC) français (Congo, République démocratique du)
4096 Friulian furlan
4096 Friulian (Italy) furlan (Italie)
103 Fulah Fulah
31847 Fulah Fulah
4096 Fulah (Cameroon) Pulaar (Kameruun)
4096 Fulah (Guinea) Pulaar (Gine)
2151 Fulah (Latin, Senegal) Fulah (Sénégal)
4096 Fulah (Mauritania) Pulaar (Muritani)
1127 Fulah (Nigeria) Pulaar (Nigeria)
86 Galician galego
1110 Galician (Galician) galego (galego)
4096 Ganda Luganda
4096 Ganda (Uganda) Luganda (Yuganda)
55 Georgian ქართული
1079 Georgian (Georgia) ქართული (საქართველო)
7 German Deutsch
3079 German (Austria) Deutsch (Österreich)

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>