2016年11月22日 星期二

Asp.Net Core MVC Paging使用了 cloudscribe.Web.Pagination

之前開發 MVC 5專案參考了 ASP.NET MVC 資料分頁 MVCPaging 2.0 應用分享文章,使用了 MVCPaging開發分頁需要的程式,但到 Core之後 MVCPaing官網建議要使用   cloudscribe.Web.Pagination library。

使用 Nuget安裝後要先設定
Startup.cs 要加上 services.AddCloudscribePagination();
_ViewImports.cshtml 要加上@addTagHelper "*, cloudscribe.Web.Pagination"

程式是最大的改變應該是在 View的部份,原本在顯示 page info的部份改寫如下:

<cs-pager asp-action="Index" asp-controller="Paging" 
     cs-pagenumber-param="page" 
     cs-paging-pagenumber="@Model.PageNumber" 
     cs-paging-pagesize="@Model.PageSize" 
     cs-paging-totalitems="@Model.TotalItemCount">
</cs-pager>

測試後的結果應該是沒問題,後續還是要測試每個 tag attribute




沒有留言:

張貼留言