久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='Xb7i8'></small><noframes id='Xb7i8'>

      • <bdo id='Xb7i8'></bdo><ul id='Xb7i8'></ul>

    1. <i id='Xb7i8'><tr id='Xb7i8'><dt id='Xb7i8'><q id='Xb7i8'><span id='Xb7i8'><b id='Xb7i8'><form id='Xb7i8'><ins id='Xb7i8'></ins><ul id='Xb7i8'></ul><sub id='Xb7i8'></sub></form><legend id='Xb7i8'></legend><bdo id='Xb7i8'><pre id='Xb7i8'><center id='Xb7i8'></center></pre></bdo></b><th id='Xb7i8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Xb7i8'><tfoot id='Xb7i8'></tfoot><dl id='Xb7i8'><fieldset id='Xb7i8'></fieldset></dl></div>

        <legend id='Xb7i8'><style id='Xb7i8'><dir id='Xb7i8'><q id='Xb7i8'></q></dir></style></legend>
      1. <tfoot id='Xb7i8'></tfoot>
      2. 標記“當前"的最佳方式菜單中的導航項

        Best way of mark the quot;currentquot; navigation item in a menu(標記“當前的最佳方式菜單中的導航項)
        <legend id='RHgff'><style id='RHgff'><dir id='RHgff'><q id='RHgff'></q></dir></style></legend>

              <tbody id='RHgff'></tbody>
              <i id='RHgff'><tr id='RHgff'><dt id='RHgff'><q id='RHgff'><span id='RHgff'><b id='RHgff'><form id='RHgff'><ins id='RHgff'></ins><ul id='RHgff'></ul><sub id='RHgff'></sub></form><legend id='RHgff'></legend><bdo id='RHgff'><pre id='RHgff'><center id='RHgff'></center></pre></bdo></b><th id='RHgff'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RHgff'><tfoot id='RHgff'></tfoot><dl id='RHgff'><fieldset id='RHgff'></fieldset></dl></div>
            • <small id='RHgff'></small><noframes id='RHgff'>

            • <tfoot id='RHgff'></tfoot>

                  <bdo id='RHgff'></bdo><ul id='RHgff'></ul>
                • 本文介紹了標記“當前"的最佳方式菜單中的導航項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  例如,在 StackOverflow 中,您可以在頂部菜單中設置以下選項:問題、標簽、用戶、徽章、未回答提問.當您位于其中一個部分時,它會以橙色突出顯示.

                  For example, here in StackOverflow you can se a top menu with the options: Questions, Tags, Users, Badges, Unanswered and Ask Question. When you are in one of those sections, it is highlighted in orange.

                  在 ASP.NET MVC 中實現這一目標的最佳方法是什么?

                  What is the best way to achieve that in ASP.NET MVC?

                  到目前為止,作為概念證明,我已經完成了這個助手:

                  So far, and as proof of concept, I have done this helper:

                      public static String IsCurrentUrl(this UrlHelper url, String generatedUrl, String output)
                      {
                          var requestedUrl = url.RequestContext.HttpContext.Request.Url;
                  
                          if (generatedUrl.EndsWith("/") && !requestedUrl.AbsolutePath.EndsWith("/"))
                              generatedUrl=generatedUrl.Substring(0, generatedUrl.Length - 1);
                  
                          if (requestedUrl.AbsolutePath.EndsWith(generatedUrl))
                              return output;
                  
                          return String.Empty;
                  
                      }
                  

                  如果當前請求與該鏈接匹配,則該方法將輸出字符串添加到元素.所以可以這樣使用:

                  That method add the output string to the element if the current request match that link. So it can be used like this:

                  <li>
                      <a href="@Url.Action("AboutUs","Home")" @Url.IsCurrentUrl(@Url.Action("AboutUs", "Home"), "class=on")><span class="bullet">About Us</span></a>
                   </li>
                  

                  第一個問題,我基本上調用了兩次Url.Action,首先是href"屬性,然后是helper,我認為必須有更好的方法來做到這一點.第二個問題,這不是比較兩個鏈接的最佳方法.我想我可以創建一個新的 Html.ActionLink 重載,所以我不需要調用 Url.Action 兩次,但是有什么內置方法可以做到這一點?

                  First problem, I am basically calling twice to Url.Action, first for the "href" attribute, and after in the helper, and I think there has to be a better way to do this. Second problem, that is not the best way to compare two links. I think I could create a new Html.ActionLink overload so I don't need to call the Url.Action twice, but is there any buil-in way to do this?

                  獎勵:如果我添加 "class="on"",MVC 會呈現 class=""on"".為什么?

                  Bonus: if I add "class="on"", MVC renders class=""on"". Why?

                  問候.

                  推薦答案

                  對于我正在進行的一個項目,我們遇到了完全相同的問題.如何突出顯示當前選項卡?這是當時采取的做法:

                  For a project that i'm working on we've had the exact same problem. How to highlight the current tab? This is the approach that was taken at the time:

                  在母版頁視圖中:

                   <% 
                     var requestActionName = 
                                           ViewContext.RouteData.Values["action"].ToString();
                     var requestControllerName = 
                                           ViewContext.RouteData.Values["controller"].ToString();
                   %>
                  
                   <li class="<%=  requestActionName.Equals("Index",
                                     StringComparison.OrdinalIgnoreCase)
                                     && requestControllerName.Equals("Home",
                                     StringComparison.OrdinalIgnoreCase) ? 
                                     "current" : string.Empty %>">
                              <%: Html.ActionLink("Home", "Index", "Home") %>
                    </li>
                  

                  基本上,我們只是將操作和控制器值與鏈接關聯的值進行字符串比較.如果它們匹配,那么我們將其稱為當前鏈接,并為菜單項分配一個當前"類.

                  Basically what's happening is that we're just string comparing the action and controller values with values associated with a link. If they match, then we're calling that the current link, and we assign a 'current' class to the menu item.

                  到目前為止,這是可行的,但是隨著我們的規模越來越大,這個設置開始變得相當大,有很多或"這個或"那個.因此,如果您決定嘗試這個,請記住這一點.

                  Now so far, this works, but as we've gotten bigger in size, this setup starts to get pretty large with a whole lot of 'or' this 'or' that. So keep that mind if you decide to try this.

                  祝你好運,希望這對你有所幫助.

                  Good luck, and hope this helps you out some.

                  這篇關于標記“當前"的最佳方式菜單中的導航項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  GoogleWebAuthorizationBroker in MVC For Google Drive Access(MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪問)
                  Why do I get System.UnauthorizedAccessException Access to the path #39;Google.Apis.Auth#39; is denied(為什么我得到 System.UnauthorizedAccessException 對路徑“Google.Apis.Auth的訪問被拒絕) - IT屋-程序員軟件開發技術分享
                  Dynamically built SiteMapPath in asp.net(在 asp.net 中動態構建的 SiteMapPath)
                  ASP.NET Exception: The remote name could not be resolved: #39;apiconnector.com#39;(ASP.NET 異常:無法解析遠程名稱:“apiconnector.com)
                  Does a MasterPage know what page is being displayed?(MasterPage 是否知道正在顯示的頁面?)
                  ASP.net MVC - Navigation and highlighting the quot;currentquot; link(ASP.net MVC - 導航和突出顯示“當前;關聯)

                      <small id='jQBys'></small><noframes id='jQBys'>

                    1. <legend id='jQBys'><style id='jQBys'><dir id='jQBys'><q id='jQBys'></q></dir></style></legend>
                          <bdo id='jQBys'></bdo><ul id='jQBys'></ul>
                        • <i id='jQBys'><tr id='jQBys'><dt id='jQBys'><q id='jQBys'><span id='jQBys'><b id='jQBys'><form id='jQBys'><ins id='jQBys'></ins><ul id='jQBys'></ul><sub id='jQBys'></sub></form><legend id='jQBys'></legend><bdo id='jQBys'><pre id='jQBys'><center id='jQBys'></center></pre></bdo></b><th id='jQBys'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jQBys'><tfoot id='jQBys'></tfoot><dl id='jQBys'><fieldset id='jQBys'></fieldset></dl></div>

                              <tbody id='jQBys'></tbody>
                            <tfoot id='jQBys'></tfoot>
                            主站蜘蛛池模板: 国产精品欧美一区二区 | 欧美成人精品 | 四虎永久免费影院 | 日韩一区二区三区在线视频 | 欧美一区二区在线播放 | pacopacomama在线 | 国产精品久久久乱弄 | 男人av在线播放 | 亚洲成人三区 | 欧美成人精品一区二区男人看 | 天堂资源| 亚洲午夜精品在线观看 | 亚洲 中文 欧美 日韩 在线观看 | 天堂久久天堂综合色 | 久久免费视频网 | 欧美一级网站 | 亚洲午夜精品一区二区三区他趣 | 成人性视频免费网站 | 欧美在线a | 国产女人与拘做受免费视频 | 亚洲精品9999久久久久 | 欧美三级视频在线观看 | 一级黄色录像毛片 | 午夜精品一区二区三区在线视频 | www九色| 欧美一区二区三区视频在线观看 | 久久久久中文字幕 | 四虎免费视频 | 亚洲高清视频在线 | 欧美性久久 | 国产福利资源在线 | 国产精品美女一区二区三区 | 精品成人av| 亚洲午夜精品一区二区三区他趣 | 亚洲免费在线观看 | 国产精品日日做人人爱 | 337p日韩 | 午夜免费精品视频 | 91av在线视频观看 | 色婷婷综合久久久久中文一区二区 | 黄色av大片|