Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does MVC generate page number selector to return HTML code

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report