偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

ASP.NET MVC 2中實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單分頁(yè)

開發(fā) 后端
在這里我們將討論的是通過(guò)一個(gè)插件實(shí)現(xiàn)ASP.NET MVC 2中的右鍵菜單和一個(gè)相當(dāng)簡(jiǎn)單的分頁(yè),希望對(duì)大家有所幫助。

右鍵菜單非常方便,很多時(shí)候會(huì)用到。這篇文章將使用一個(gè)JQUERY的插件在ASP.NET MVC中實(shí)現(xiàn)右鍵菜單。本文還將介紹一下在ASP.NET MVC中如何實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)。效果如下圖:

首先,下載此插件。

新建一個(gè)asp.net mvc應(yīng)用程序。將此插件放入Scripts文件夾。并在頁(yè)面上引用。

這個(gè)demo使用到NORTHWND數(shù)據(jù)庫(kù)的Product表。

定義右鍵菜單:

  1. <div class="contextMenu" id="myMenu1"> <ul>   
  2. <li id="detail">
  3. <img src="http://www.cnblogs.com/Content/detail.ico" />detail</li>   
  4. <li id="new"><img src="http://www.cnblogs.com/Content/new.ico" />new</li>
  5. <li id="delete"> 
  6. <img src="http://www.cnblogs.com/Content/delete.ico"/>delete</li>   
  7. <li id="modify">
  8. <img src="http://www.cnblogs.com/Content/modify.ico"/>modify</li>   
  9.  </ul> </div> 

將此菜單定義在產(chǎn)品名上,故在在產(chǎn)品名上添加一個(gè)class供jquery選擇。

  1. <td class="showContext" id="<%= item.ProductID %>">
  2. <%: item.ProductName %></td> 

在頁(yè)面上插入下面腳本。用于綁定菜單項(xiàng)的行為。為了簡(jiǎn)單起見,將所以的菜單項(xiàng)的行為都定義成導(dǎo)航到詳情頁(yè)面.

  1. <script type="text/javascript">   
  2.    $(document).ready(function () {   
  3.       $('td.showContext').contextMenu('myMenu1', {   
  4.          bindings: {  
  5.                'detail'function (t) {   
  6.            document.location.href = '/Products/Detail/'+t.id;   
  7.                 },   
  8.                'new'function (t) {  
  9.          document.location.href = '/Products/Detail/' + t.id;  
  10.               },  
  11.                  'delete'function (t) {  
  12.                      confirm("你確定刪除嗎?");  
  13.           document.location.href = '/Products/Detail/' + t.id;  
  14.                 },  
  15.                  'modify'function (t) {  
  16.        document.location.href = '/Products/Detail/' + t.id;  
  17.                }  
  18.              }  
  19.         });  
  20.      });  
  21. </script> 

這樣就非常簡(jiǎn)單的實(shí)現(xiàn)了右鍵菜單的功能。

下面說(shuō)下實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)。asp.net mvc中分頁(yè)非常簡(jiǎn)單。

看下面定義的table的html代碼:

  1.  <table>   
  2.   <tr>   
  3.             <th>   
  4.                 ProductName   
  5.              </th> 
  6.           <th>   
  7.                SupplierID   
  8.             </th>   
  9.             <th> 
  10.                CategoryID11             </th> 
  11.             <th> 
  12.                  QuantityPerUnit  
  13.           </th> 
  14.             <th> 
  15.                  UnitPrice  
  16.            </th> 
  17.              <th> 
  18.                 UnitsInStock20             </th> 
  19.            <th> 
  20.                  UnitsOnOrder23             </th> 
  21.              <th> 
  22.                 ReorderLevel  
  23.             </th> 
  24.             <th> 
  25.                 Discontinued  
  26.              </th> 
  27.          </tr> 
  28.     <% foreach (var item in Model.Products)  
  29.         { %> 
  30.         <tr> 
  31.   <td class="showContext" id="<%= item.ProductID %>"> 
  32. <%: item.ProductName %></td> 
  33.              <td> 
  34.                  <%: item.SupplierID %> 
  35.            </td> 
  36.              <td> 
  37.                 <%: item.CategoryID %> 
  38.             </td> 
  39.              <td> 
  40.                 <%: item.QuantityPerUnit %> 
  41.              </td> 
  42.              <td> 
  43.        <%: String.Format("{0:F}", item.UnitPrice) %> 
  44.             </td> 
  45.              <td> 
  46.                 <%: item.UnitsInStock %> 
  47.              </td> 
  48.           <td> 
  49.              <%: item.UnitsOnOrder %> 
  50.              </td> 
  51.           <td> 
  52.            <%: item.ReorderLevel %> 
  53.             </td> 
  54.             <td> 
  55.                <%: item.Discontinued %> 
  56.           </td> 
  57.         </tr>      
  58.     <% } %> 
  59. </table> 

我們只要在這個(gè)table下面插入一段分頁(yè)的HTML腳本就行了。分頁(yè)的腳本當(dāng)然要生成,使用Htmlhelper的擴(kuò)展方法去生成這個(gè)腳本??聪旅娴臄U(kuò)展方法,非常的簡(jiǎn)單的生成了分頁(yè)的html代碼:

  1. public static string Pager(this HtmlHelper helper, int currentPage, int currentPageSize, int totalRecords, string urlPrefix)   
  2.         {  
  3.            StringBuilder sb1 = new StringBuilder();   
  4. int seed = currentPage % currentPageSize == 0 ? currentPage : currentPage - (currentPage % currentPageSize);   
  5. if (currentPage > 0)   
  6. sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, currentPage));   
  7. if (currentPage - currentPageSize >= 0)  
  8. sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (currentPage - currentPageSize) + 1));  
  9. for (int i = seed; i < Math.Round((totalRecords / 10) + 0.5) && i < seed + currentPageSize; i++)  
  10.  {  
  11. sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1));  
  12.  }  
  13. if (currentPage + currentPageSize <= (Math.Round((totalRecords / 10) + 0.5) - 1))  
  14. sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (currentPage + currentPageSize) + 1));  
  15. if (currentPage < (Math.Round((totalRecords / 10) + 0.5) - 1))  
  16. sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, currentPage + 2));  
  17. return sb1.ToString();  

然后在table后面添加下面的代碼,在table下面輸出分頁(yè)的html代碼:

 
  1. <div class="pager">   
  2. <%=Html.Pager(Model.CurrentPage, Model.TotalPages,Model.TotalItems ,"/Products/List")%>
  3.    </div> 

這樣就完成分頁(yè)和右鍵菜單的功能了。是不是非常的簡(jiǎn)單呢。:)

效果:

效果

顯示:

右鍵菜單

如果有興趣可以下載代碼。

總結(jié):在asp.net mvc中實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單的分頁(yè)。

代碼http://cid-aef1e64945224a20.office.live.com/self.aspx/.Public/ContextMenuDemo.rar

原文標(biāo)題:ASP.NET MVC2右鍵菜單和最簡(jiǎn)單分頁(yè)

鏈接:http://www.cnblogs.com/zhuqil/archive/2010/08/01/asp-net-mvc-context-menu-and-simple-paging.html

【編輯推薦】

  1. 添加設(shè)置ASP.NET Web時(shí)出現(xiàn)問(wèn)題
  2. 詳細(xì)說(shuō)明ASP.NET 2.0功能支持
  3. 強(qiáng)化部署ASP.Net 2.0配置應(yīng)用程序
  4. 微軟PDC2009直擊:改進(jìn)ASP.NET 4運(yùn)行時(shí)
  5. 詳解ASP.NET MVC 2自定義驗(yàn)證

 

 

責(zé)任編輯:彭凡 來(lái)源: 博客園
相關(guān)推薦

2009-07-22 16:02:39

ASP.NET MVCPagedList

2009-07-28 14:47:18

ASP.NET MVC

2009-09-10 09:50:47

ASP.NET MVC

2010-03-19 09:17:16

ASP.NET MVC

2009-07-20 15:44:32

ASP.NET MVC

2012-04-13 10:05:24

ASP.NET

2010-02-03 09:50:58

ASP.NET MVC

2009-07-31 12:43:59

ASP.NET MVC

2010-01-26 13:15:42

ASP.NET MVC

2009-12-21 10:05:10

ASP.NET MVC

2009-07-24 13:20:44

MVC框架ASP.NET

2009-04-20 09:43:37

ASP.NET MVC基礎(chǔ)開發(fā)

2012-04-23 15:10:18

ASP.NET

2010-10-14 09:05:36

ASP.NET MVC

2009-07-30 14:32:18

ASP.NET常用代碼

2009-06-12 09:24:34

ASP.NET窗體ASP.NET MVC

2009-07-22 13:24:24

ASP.NET MVC

2009-07-22 10:09:59

ASP.NET MVC

2009-07-23 14:31:20

ASP.NET MVC

2009-07-23 15:44:39

ASP.NET MVC
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)