成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

ASP.NET MVC 2中實現右鍵菜單和簡單分頁

開發 后端
在這里我們將討論的是通過一個插件實現ASP.NET MVC 2中的右鍵菜單和一個相當簡單的分頁,希望對大家有所幫助。

右鍵菜單非常方便,很多時候會用到。這篇文章將使用一個JQUERY的插件在ASP.NET MVC中實現右鍵菜單。本文還將介紹一下在ASP.NET MVC中如何實現簡單的分頁。效果如下圖:

首先,下載此插件

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

這個demo使用到NORTHWND數據庫的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> 

將此菜單定義在產品名上,故在在產品名上添加一個class供jquery選擇。

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

在頁面上插入下面腳本。用于綁定菜單項的行為。為了簡單起見,將所以的菜單項的行為都定義成導航到詳情頁面.

  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> 

這樣就非常簡單的實現了右鍵菜單的功能。

下面說下實現簡單的分頁。asp.net mvc中分頁非常簡單。

看下面定義的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> 

我們只要在這個table下面插入一段分頁的HTML腳本就行了。分頁的腳本當然要生成,使用Htmlhelper的擴展方法去生成這個腳本。看下面的擴展方法,非常的簡單的生成了分頁的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下面輸出分頁的html代碼:

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

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

效果:

效果

顯示:

右鍵菜單

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

總結:在asp.net mvc中實現右鍵菜單和簡單的分頁。

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

原文標題:ASP.NET MVC2右鍵菜單和最簡單分頁

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

【編輯推薦】

  1. 添加設置ASP.NET Web時出現問題
  2. 詳細說明ASP.NET 2.0功能支持
  3. 強化部署ASP.Net 2.0配置應用程序
  4. 微軟PDC2009直擊:改進ASP.NET 4運行時
  5. 詳解ASP.NET MVC 2自定義驗證

 

 

責任編輯:彭凡 來源: 博客園
相關推薦

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

2012-04-13 10:05:24

ASP.NET

2009-07-20 15:44:32

ASP.NET MVC

2010-02-03 09:50:58

ASP.NET MVC

2009-07-24 13:20:44

MVC框架ASP.NET

2009-07-31 12:43:59

ASP.NET MVC

2010-01-26 13:15:42

ASP.NET MVC

2009-04-20 09:43:37

ASP.NET MVC基礎開發

2009-12-21 10:05:10

ASP.NET MVC

2012-04-23 15:10:18

ASP.NET

2010-10-14 09:05:36

ASP.NET MVC

2009-06-12 09:24:34

ASP.NET窗體ASP.NET MVC

2010-11-02 08:46:55

NupackASP.NET MVC

2009-07-22 13:16:04

MvcAjaxPaneASP.NET MVC

2009-07-30 14:32:18

ASP.NET常用代碼

2009-09-09 09:09:17

ASP.NET MVC

2009-07-22 13:24:24

ASP.NET MVC
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产在线一区二区三区 | 91精品久久久久久久久久入口 | 亚洲激情在线观看 | 国产精品久久久乱弄 | 在线免费中文字幕 | 午夜一区| 精品久久久久久亚洲精品 | 一a一片一级一片啪啪 | 国产乱码精品1区2区3区 | 欧美激情视频一区二区三区在线播放 | 成人久久18免费网站图片 | 日本手机看片 | 国产精品免费一区二区三区 | 一区视频在线免费观看 | 国产午夜视频 | 亚洲精品一区二区三区中文字幕 | 日韩福利片 | 精品无码久久久久国产 | 色综合久久久久 | 麻豆国产精品777777在线 | 伊人久久精品一区二区三区 | 91精品亚洲 | 欧美国产中文字幕 | 欧美综合一区 | 国产一级淫片a直接免费看 免费a网站 | 91国在线观看 | 日日爱夜夜操 | 男人天堂手机在线视频 | а√中文在线8 | 国内精品久久久久久 | 丁香综合 | 日日夜精品视频 | 欧美日韩成人在线 | 天堂久久av | 伊人免费观看视频 | 一区二区三区不卡视频 | 成人免费日韩 | 亚洲国产一区在线 | 欧美中文字幕 | 中文字幕亚洲视频 | 精品综合网|