欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

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

本篇文章為大家展示了ASP.NET MVC 2中如何實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單分頁(yè),內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、廣平網(wǎng)絡(luò)推廣、小程序制作、廣平網(wǎng)絡(luò)營(yíng)銷、廣平企業(yè)策劃、廣平品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供廣平建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:chinadenli.net

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

ASP.NET MVC 2中如何實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單分頁(yè)首先,下載此插件。

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

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

定義右鍵菜單:

<div class="contextMenu" id="myMenu1"> <ul>   <li id="detail"><img src="http://www.cnblogs.com/Content/detail.ico" />detail</li>   <li id="new"><img src="http://www.cnblogs.com/Content/new.ico" />new</li><li id="delete"> <img src="http://www.cnblogs.com/Content/delete.ico"/>delete</li>   <li id="modify"><img src="http://www.cnblogs.com/Content/modify.ico"/>modify</li>    </ul> </div>

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

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

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

<script type="text/javascript">      $(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("你確定刪除嗎?");            document.location.href = '/Products/Detail/' + t.id;                  },                   'modify': function (t) {         document.location.href = '/Products/Detail/' + t.id;                 }               }          });       });  </script>

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

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

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

 <table>     <tr>               <th>                   ProductName                </th>           <th>                  SupplierID               </th>               <th>                CategoryID11             </th>             <th>                  QuantityPerUnit            </th>             <th>                  UnitPrice             </th>              <th>                 UnitsInStock20             </th>            <th>                  UnitsOnOrder23             </th>              <th>                 ReorderLevel              </th>             <th>                 Discontinued               </th>          </tr>     <% foreach (var item in Model.Products)          { %>         <tr>   <td class="showContext" id="<%= item.ProductID %>"> <%: item.ProductName %></td>              <td>                  <%: item.SupplierID %>            </td>              <td>                 <%: item.CategoryID %>             </td>              <td>                 <%: item.QuantityPerUnit %>              </td>              <td>        <%: String.Format("{0:F}", item.UnitPrice) %>             </td>              <td>                 <%: item.UnitsInStock %>              </td>           <td>              <%: item.UnitsOnOrder %>              </td>           <td>            <%: item.ReorderLevel %>             </td>             <td>                <%: item.Discontinued %>           </td>         </tr>          <% } %> </table>

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

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("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, currentPage));   if (currentPage - currentPageSize >= 0)  sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (currentPage - currentPageSize) + 1));  for (int i = seed; i < Math.Round((totalRecords / 10) + 0.5) && i < seed + currentPageSize; i++)   {  sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1));   }  if (currentPage + currentPageSize <= (Math.Round((totalRecords / 10) + 0.5) - 1))  sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (currentPage + currentPageSize) + 1));  if (currentPage < (Math.Round((totalRecords / 10) + 0.5) - 1))  sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, currentPage + 2));  return sb1.ToString();  }

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

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

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

效果:

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

顯示:

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

上述內(nèi)容就是ASP.NET MVC 2中如何實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單分頁(yè),你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站題目:ASP.NETMVC2中如何實(shí)現(xiàn)右鍵菜單和簡(jiǎn)單分頁(yè)
文章來(lái)源:http://chinadenli.net/article6/gchsog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站排名、企業(yè)建站、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)