Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
4096 English (Sudan) English (Sudan)
4096 English (Swaziland) English (Swaziland)
4096 English (Sweden) English (Sweden)
4096 English (Switzerland) English (Switzerland)
4096 English (Tanzania) English (Tanzania)
4096 English (Tokelau) English (Tokelau)
4096 English (Tonga) English (Tonga)
11273 English (Trinidad and Tobago) English (Trinidad and Tobago)
4096 English (Turks and Caicos Islands) English (Turks and Caicos Islands)
4096 English (Tuvalu) English (Tuvalu)
4096 English (U.S. Outlying Islands) English (U.S. Outlying Islands)
4096 English (U.S. Virgin Islands) English (U.S. Virgin Islands)
4096 English (Uganda) English (Uganda)
2057 English (United Kingdom) English (United Kingdom)
1033 English (United States) English (United States)
4096 English (Vanuatu) English (Vanuatu)
4096 English (World) English (World)
4096 English (Zambia) English (Zambia)
12297 English (Zimbabwe) English (Zimbabwe)
4096 Esperanto esperanto
4096 Esperanto (World) esperanto (World)
37 Estonian eesti
1061 Estonian (Estonia) eesti (Eesti)
4096 Ewe Eʋegbe
4096 Ewe (Ghana) Eʋegbe (Ghana nutome)
4096 Ewe (Togo) Eʋegbe (Togo nutome)
4096 Ewondo ewondo
4096 Ewondo (Cameroon) ewondo (Kamərún)
56 Faroese føroyskt
4096 Faroese (Denmark) føroyskt (Danmark)
1080 Faroese (Faroe Islands) føroyskt (Føroyar)
100 Filipino Filipino
1124 Filipino (Philippines) Filipino (Pilipinas)
11 Finnish suomi
1035 Finnish (Finland) suomi (Suomi)
12 French français
4096 French (Algeria) français (Algérie)
2060 French (Belgium) français (Belgique)
4096 French (Benin) français (Bénin)
4096 French (Burkina Faso) français (Burkina Faso)
4096 French (Burundi) français (Burundi)
11276 French (Cameroon) français (Cameroun)
3084 French (Canada) français (Canada)
7180 French (Caribbean) français (caraïbes)
4096 French (Central African Republic) français (République centrafricaine)
4096 French (Chad) français (Tchad)
4096 French (Comoros) français (Comores)
4096 French (Congo) français (Congo)
12300 French (Côte d’Ivoire) français (Côte d’Ivoire)
4096 French (Djibouti) français (Djibouti)

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>