日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
ASP.NET MVC 2中實現(xiàn)右鍵菜單和簡單分頁

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

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供冀州企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計、網(wǎng)站制作、H5頁面制作、小程序制作等業(yè)務(wù)。10年已為冀州眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

首先,下載此插件。

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

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

定義右鍵菜單:

 
 
 
 
  1.  
         
    • detail
    •    
    • new
    •  
    • delete
    •    
    • modify
    •    
    •  
     
 

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

 
 
 
 
  1. ">
  2. <%: item.ProductName %> 

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

 
 
 
 
  1.  

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

下面說下實現(xiàn)簡單的分頁。asp.net mvc中分頁非常簡單。

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

 
 
 
 
  1.     
  2.   
  3.    
  4.             
  5.  
  6.           
  7.    
  8.             
  9.  
  10.             
  11.  
  12.             
  13.  
  14.              
  15.  
  16.            
  17.  
  18.              
  19.  
  20.             
  21.  
  22.          
  23.  
  24.     <% foreach (var item in Model.Products)  
  25.         { %> 
  26.         
  27.  
  28.   "> 
  29. <%: item.ProductName %> 
  30.              
  31.  
  32.              
  33.  
  34.              
  35.  
  36.              
  37.  
  38.              
  39.  
  40.           
  41.  
  42.           
  43.  
  44.             
  45.  
  46.         
  47.       
  48.     <% } %> 
  49.    
  50.                 ProductName   
  51.              
  52.    
  53.                SupplierID   
  54.             
  55.  
  56.                CategoryID11             
  57.  
  58.                  QuantityPerUnit  
  59.           
  60.  
  61.                  UnitPrice  
  62.            
  63.  
  64.                 UnitsInStock20             
  65.  
  66.                  UnitsOnOrder23             
  67.  
  68.                 ReorderLevel  
  69.             
  70.  
  71.                 Discontinued  
  72.              
  73.  
  74.                  <%: item.SupplierID %> 
  75.            
  76.  
  77.                 <%: item.CategoryID %> 
  78.             
  79.  
  80.                 <%: item.QuantityPerUnit %> 
  81.              
  82.  
  83.        <%: String.Format("{0:F}", item.UnitPrice) %> 
  84.             
  85.  
  86.                 <%: item.UnitsInStock %> 
  87.              
  88.  
  89.              <%: item.UnitsOnOrder %> 
  90.              
  91.  
  92.            <%: item.ReorderLevel %> 
  93.             
  94.  
  95.                <%: item.Discontinued %> 
  96.           
  97.  

我們只要在這個table下面插入一段分頁的HTML腳本就行了。分頁的腳本當(dāng)然要生成,使用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("Previous", urlPrefix, currentPage));   
  7. if (currentPage - currentPageSize >= 0)  
  8. sb1.AppendLine(String.Format("...", 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("{1}", urlPrefix, i + 1));  
  12.  }  
  13. if (currentPage + currentPageSize <= (Math.Round((totalRecords / 10) + 0.5) - 1))  
  14. sb1.AppendLine(String.Format("...", urlPrefix, (currentPage + currentPageSize) + 1));  
  15. if (currentPage < (Math.Round((totalRecords / 10) + 0.5) - 1))  
  16. sb1.AppendLine(String.Format("Next", urlPrefix, currentPage + 2));  
  17. return sb1.ToString();  

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

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

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

效果:

顯示:

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

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

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


網(wǎng)站題目:ASP.NET MVC 2中實現(xiàn)右鍵菜單和簡單分頁
當(dāng)前地址:http://m.5511xx.com/article/cosoioi.html