Paging TagHelper - Ajax >= v4.0

Ajax Sample : Cultures Table

LCID English Name Native Name
4096 Ngiemboon Shwóŋò ngiembɔɔn
4096 Ngiemboon (Cameroon) Shwóŋò ngiembɔɔn (Kàmalûm)
4096 Ngomba Ndaꞌa
4096 Ngomba (Cameroon) Ndaꞌa (Kamɛlûn)
4096 N'ko ߒߞߏ
4096 N'ko (Guinea) ߒߞߏ (ߖߌ߬ߣߍ߬ ߞߊ߲ߓߍ߲)
4096 North Ndebele isiNdebele
4096 North Ndebele (Zimbabwe) isiNdebele (Zimbabwe)
4096 Northern Luri لۊری شومالی
4096 Northern Luri (Iran) لۊری شومالی (Iran)
4096 Northern Luri (Iraq) لۊری شومالی (Iraq)
59 Northern Sami davvisámegiella
20 Norwegian norsk
31764 Norwegian Bokmål norsk bokmål
1044 Norwegian Bokmål (Norway) norsk bokmål (Norge)
4096 Norwegian Bokmål (Svalbard and Jan Mayen) norsk bokmål (Svalbard og Jan Mayen)
30740 Norwegian Nynorsk nynorsk
2068 Norwegian Nynorsk (Norway) nynorsk (Noreg)
4096 Nuer Thok Nath
4096 Nuer (South Sudan) Thok Nath (South Sudan)
4096 Nyankole Runyankore
4096 Nyankole (Uganda) Runyankore (Uganda)
130 Occitan Occitan
1154 Occitan (France) Occitan (França)
72 Odia ଓଡ଼ିଆ
1096 Odia (India) ଓଡ଼ିଆ (ଭାରତ)
114 Oromo Oromoo
1138 Oromo (Ethiopia) Oromoo (Itoophiyaa)
4096 Oromo (Kenya) Oromoo (Keeniyaa)
4096 Ossetic ирон
4096 Ossetic (Georgia) ирон (Гуырдзыстон)
4096 Ossetic (Russia) ирон (Уӕрӕсе)
121 Papiamento Papiamentu
1145 Papiamento (Caribbean) Papiamentu (Caribbean)
99 Pashto پښتو
1123 Pashto (Afghanistan) پښتو (افغانستان)
41 Persian فارسی
1065 Persian (Iran) فارسی (ایران)
21 Polish polski
1045 Polish (Poland) polski (Polska)
22 Portuguese português
4096 Portuguese (Angola) português (Angola)
1046 Portuguese (Brazil) português (Brasil)
4096 Portuguese (Cabo Verde) português (Cabo Verde)
4096 Portuguese (Equatorial Guinea) português (Guiné Equatorial)
4096 Portuguese (Guinea-Bissau) português (Guiné-Bissau)
4096 Portuguese (Luxembourg) português (Luxemburgo)
4096 Portuguese (Macao SAR) português (RAE de Macau)
4096 Portuguese (Mozambique) português (Moçambique)
2070 Portuguese (Portugal) português (Portugal)

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>