Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
4096 Asturian asturianu
4096 Asturian (Spain) asturianu (España)
4096 Asu Kipare
4096 Asu (Tanzania) Kipare (Tadhania)
44 Azerbaijani azərbaycan
29740 Azerbaijani (Cyrillic) Азәрбајҹан дили
2092 Azerbaijani (Cyrillic, Azerbaijan) азәрбајҹан (Азәрбајҹан)
30764 Azerbaijani (Latin) azərbaycan
1068 Azerbaijani (Latin, Azerbaijan) azərbaycan (Azərbaycan)
4096 Bafia rikpa
4096 Bafia (Cameroon) rikpa (kamɛrún)
4096 Bamanankan bamanakan
4096 Bamanankan (Latin) bamanakan
4096 Bamanankan (Latin, Mali) bamanakan (Mali)
69 Bangla বাংলা
2117 Bangla (Bangladesh) বাংলা (বাংলাদেশ)
1093 Bangla (India) বাংলা (ভারত)
4096 Basaa Ɓàsàa
4096 Basaa (Cameroon) Ɓàsàa (Kàmɛ̀rûn)
109 Bashkir Башҡорт
1133 Bashkir (Russia) Башҡорт (Рәсәй)
45 Basque euskara
1069 Basque (Basque) euskara (euskara)
35 Belarusian Беларуская
1059 Belarusian (Belarus) Беларуская (Беларусь)
4096 Bemba Ichibemba
4096 Bemba (Zambia) Ichibemba (Zambia)
4096 Bena Hibena
4096 Bena (Tanzania) Hibena (Hutanzania)
4096 Blin ብሊን
4096 Blin (Eritrea) ብሊን (ኤርትራ)
4096 Bodo बड़ो
4096 Bodo (India) बड़ो (भारत)
30746 Bosnian bosanski
25626 Bosnian (Cyrillic) босански
8218 Bosnian (Cyrillic, Bosnia and Herzegovina) босански (Босна и Херцеговина)
26650 Bosnian (Latin) bosanski
5146 Bosnian (Latin, Bosnia and Herzegovina) bosanski (Bosna i Hercegovina)
126 Breton brezhoneg
1150 Breton (France) brezhoneg (Frañs)
2 Bulgarian български
1026 Bulgarian (Bulgaria) български (България)
85 Burmese ဗမာ
1109 Burmese (Myanmar) မြန်မာ (မြန်မာ)
3 Catalan català
4096 Catalan (Andorra) català (Andorra)
1027 Catalan (Catalan) català (català)
4096 Catalan (France) català (França)
4096 Catalan (Italy) català (Itàlia)
95 Central Atlas Tamazight Tamaziɣt n laṭlaṣ

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>