Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
7227 Sami, Southern (Sweden) åarjelsaemiengïele (Sveerje)
4096 Sango Sängö
4096 Sango (Central African Republic) Sängö (Ködörösêse tî Bêafrîka)
4096 Sangu Ishisangu
4096 Sangu (Tanzania) Ishisangu (Tansaniya)
79 Sanskrit संस्कृत
1103 Sanskrit (India) संस्कृत (भारतम्)
145 Scottish Gaelic Gàidhlig
1169 Scottish Gaelic (United Kingdom) Gàidhlig (An Rìoghachd Aonaichte)
4096 Sena sena
4096 Sena (Mozambique) sena (Moçambique)
31770 Serbian srpski
27674 Serbian (Cyrillic) српски
7194 Serbian (Cyrillic, Bosnia and Herzegovina) српски (Босна и Херцеговина)
4096 Serbian (Cyrillic, Kosovo) српски (Косово)
12314 Serbian (Cyrillic, Montenegro) српски (Црна Гора)
10266 Serbian (Cyrillic, Serbia) српски (Србија)
28698 Serbian (Latin) srpski
6170 Serbian (Latin, Bosnia and Herzegovina) srpski (Bosna i Hercegovina)
4096 Serbian (Latin, Kosovo) srpski (Kosovo)
11290 Serbian (Latin, Montenegro) srpski (Crna Gora)
9242 Serbian (Latin, Serbia) srpski (Srbija)
48 Sesotho Sesotho
4096 Sesotho (Lesotho) Sesotho (Lesotho)
1072 Sesotho (South Africa) Sesotho (South Africa)
108 Sesotho sa Leboa Sesotho sa Leboa
1132 Sesotho sa Leboa (South Africa) Sesotho sa Leboa (Afrika Borwa)
50 Setswana Setswana
2098 Setswana (Botswana) Setswana (Botswana)
1074 Setswana (South Africa) Setswana (Aforika Borwa)
4096 Shambala Kishambaa
4096 Shambala (Tanzania) Kishambaa (Tanzania)
4096 Shona chiShona
4096 Shona (Latin) chiShona (Latin)
4096 Shona (Latin, Zimbabwe) chiShona (Zimbabwe)
89 Sindhi سنڌي
31833 Sindhi سنڌي
4096 Sindhi (Devanagari) सिन्धी
1113 Sindhi (Devanagari, India) सिन्धी (India)
2137 Sindhi (Pakistan) سنڌي (پاکستان)
91 Sinhala සිංහල
1115 Sinhala (Sri Lanka) සිංහල (ශ්‍රී ලංකාව)
4096 siSwati Siswati
4096 siSwati (South Africa) siSwati (South Africa)
4096 siSwati (Swaziland) siSwati (Swaziland)
27 Slovak slovenčina
1051 Slovak (Slovakia) slovenčina (Slovensko)
36 Slovenian slovenščina
1060 Slovenian (Slovenia) slovenščina (Slovenija)
4096 Soga Olusoga

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>