Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of asp.netmvc Custom pager Encapsulation and Optimization

Shulou Source: shulou.com Published: 2022-06-03 13:02:14 10月03日 Update

In this issue, the editor will bring you an example analysis of asp.netmvc custom pager encapsulation and optimization. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

HtmlHelper Pager extension

Pager V1.0:

/ Pager V1.0 / HtmlHelper / paging information / public static MvcHtmlString Pager (this HtmlHelper helper, PagerModel pager) {StringBuilder sbHtmlText = new StringBuilder (); sbHtmlText.Append (""); if (pager.PageIndex = pager.PageCount) {sbHtmlText.Append ("»");} else {sbHtmlText.AppendFormat ("{0}", pager.PageIndex + 1) SbHtmlText.AppendFormat ("»", pager.PageIndex + 1);} sbHtmlText.Append ("); sbHtmlText.AppendFormat (" {0} data per page, a total of {1} pages, a total of {2} data ", pager.PageSize, pager.PageCount, pager.TotalCount); return MvcHtmlString.Create (sbHtmlText.ToString ());}

Pager V2.0

/ Pager V2.0 / HtmlHelper / pagination information / paging event / public static MvcHtmlString Pager (this HtmlHelper helper, PagerModel pager, Func onPageChange) {StringBuilder sbHtmlText = new StringBuilder (); sbHtmlText.Append ("); if (pager.PageIndex = pager.PageCount) {sbHtmlText.Append (" »") } else {sbHtmlText.AppendFormat ("{1}", onPageChange (pager.PageIndex + 1), pager.PageIndex + 1); sbHtmlText.AppendFormat ("»", onPageChange (pager.PageIndex + 1));} sbHtmlText.Append ("); sbHtmlText.AppendFormat (" {0} data per page, a total of {1} pages, a total of {2} data ", pager.PageSize, pager.PageCount, pager.TotalCount) Return MvcHtmlString.Create (sbHtmlText.ToString ());}

Pager V3.0

/ Pager V3.0 / HtmlHelper / paging information / paging address or event / pagination view name / paging display mode / public static MvcHtmlString Pager (this HtmlHelper helper, PagerModel pager, Func onPageChange, string pagerViewName, PagingDisplayMode displayMode = PagingDisplayMode.Always) {pager.OnPageChange = onPageChange; pager.PagingDisplayMode = displayMode Return MvcHtmlString.Create (helper.Partial (pagerViewName, pager). ToHtmlString ();}

Summary

Pager V1.0 paging style and page flipping events all need to modify the CSharp code if you want to modify it.

Pager V2.0 can customize the paging event, but you still need to modify the CSharp code to change the paging style.

Pager V3.0 can modify the page flip event or address and paging style in a custom paging view

End

Now that the project MvcSimplePager is packaged into Nuget http://www.nuget.org/packages/MvcSimplePager/, you can search for MvcSimplePager in the nuget package manager in VS to use it.

Customize the MvcSimplePager project and sample code: https://github.com/WeihanLi/MvcSimplePager, you can customize it as needed.

The above is the example of asp.netmvc custom pager encapsulation and optimization shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Events analysis data examples code information styles encapsulation content divisions addresses views projects professional small and medium rich content names that is articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Docker Xiaomi vpn