Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does MVC generate page number selector to return HTML code

Shulou Source: shulou.com Published: 2022-05-31 13:13:28 09月25日 Update

This article mainly introduces MVC how to generate page selector to return HTML code related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this MVC how to generate page selector return HTML code article will have a harvest, let's take a look at it.

The style is the paging "pagination" in bootstrap3, which is not big if you don't use bootstrap to present it separately.

The page number generation code is:

Public string GetPaginationHtml (PaginationViewModel p) {var PageNum = p.PageCountX / current page number (page number starts from 1) var PageCount = p.PageCountX / total number of pages var ItemCount = p.ItemCountX / total number of pages var showPageNum = 6 new StringBuilder / number of pages showing numbers var html = new StringBuilder (); html.Append (", p.ULID, p.Data)) / / ULID and Data are if (PageCount > 1) {var startPage = 1; if (showPageNum > PageCount) {startPage = 1;} else {if (PageNum-(showPageNum / 2) = PageCount) {startPage = PageCount-showPageNum;} else {startPage = PageNum-(showPageNum / 2) }} startPage = (startPage = = 0? 1: startPage); / / the first page number to start displaying numbers / / the previous page button html.Append (string.Format ("previous page", PageNum 1) / / generate the first page button and the middle ellipsis {html.Append ("{2}", I = = PageNum? "active": ", I, I));} / / generate the last page button and the middle ellipsis int maxShowPage = startPage + showPageNum; if (maxShowPage = PageCount? "disabled": ", PageNum + 1)); / / display page number information html.Append (string.Format (" {0} page {1} {2} content ", PageNum, PageCount, ItemCount));} else {/ / content displayed when less than one page html.Append (string.Format (" 1 page {0} content ", ItemCount));} return html.ToString ();}

When you use it, put it directly into MVC Controllers and ActionResult returns Content (html).

On the page, you can directly

@ Html.Action ("", new {page = 1pageSize = 20,...})

Also OK

$.ajax ({url:'/ Function/FileArchiveSelectShouWenDengJiTableMessage', type: 'post', dataType:' html', data: {page: page, pageSize: pagesize,...},}) .done (function (data) {$('# ShouWenPageSelect') .html (data); InitPageSelectEvent ();}); this is the end of the article on "how MVC generates the HTML code returned by the page selector". Thank you for reading! I believe that everyone has a certain understanding of "how to generate MVC page selector return HTML code" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.

Tags: Page number generation content code selection button knowledge number ellipsis article page previous small event value information foreground simple operation quantity article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Xiaomi macOS NVidia