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 to realize ASP.NET MVC 2 right-click menu and simple paging

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use ASP.NET MVC 2 right-click menu and simple paging". In daily operation, I believe many people have doubts about how to use ASP.NET MVC 2 right-click menu and simple paging. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use ASP.NET MVC 2 right-click menu and simple paging". Next, please follow the editor to study!

The right-click menu is very convenient and is often used. This article will use a plug-in for JQUERY to implement right-click menus in ASP.NET MVC. This article also shows you how to implement simple paging in ASP.NET MVC. The effect is as follows:

Create a new asp.net mvc application. Put this plug-in in the Scripts folder. And quote it on the page.

Define the right-click menu:

Detail

New

Delete

Modify

Define this menu on the product name, so add a class to the product name for jquery to choose from.

Insert the following script on the page. The behavior used to bind menu items. For simplicity, define the behavior of all menu items as navigating to the details page.

$(document) .ready (function () {$('td.showContext'). ContextMenu (' myMenu1', {bindings: {'detail': function (t) {_ document.location.href =' / Products/Detail/'+t.id;}, 'new': function (t) {_ document.location.href =' / Products/Detail/'+t.id) }, 'delete': function (t) {confirm ("are you sure to delete?") ; _ document.location.href ='/ Products/Detail/' + t.id;}, 'modify': function (t) {_ document.location.href =' / Products/Detail/' + t.id;}});})

In this way, it is very simple to realize the function of right-click menu.

Let's talk about implementing simple paging. Paging in asp.net mvc is very simple.

Take a look at the html code for table defined below:

ProductName SupplierID CategoryID11 QuantityPerUnit UnitPrice UnitsInStock20 UnitsOnOrder23 ReorderLevel Discontinued

All we have to do is insert a paged HTML script under the table. Of course, the paging script is generated, using the extension method of Htmlhelper to generate the script. Look at the following extension method, which is very simple to generate paged html code:

Public static string Pager (this HtmlHelper helper, int currentPage, int currentPageSize, int totalRecords, string urlPrefix) {StringBuilder sb1 = new StringBuilder (); int seed = currentPage% currentPageSize = 0? CurrentPage: currentPage-(currentPage% currentPageSize); if (currentPage > 0) sb1.AppendLine (String.Format ("Previous", urlPrefix, currentPage); if (currentPage-currentPageSize > = 0) sb1.AppendLine (String.Format ("...", urlPrefix, (currentPage-currentPageSize) + 1)); for (int I = seed; I < Math.Round ((totalRecords / 10) + 0.5) & I < seed + currentPageSize; I +) {sb1.AppendLine (String.Format ("{1}", urlPrefix, I + 1)) } if (currentPage + currentPageSize)

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

Development

Wechat

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

12
Report