MVC導覽功能表高亮顯示實現思路

來源:互聯網
上載者:User

標籤:style   blog   color   使用   os   io   for   ar   

///代碼不是我寫的,但是已經親自測試過了,按照我的理解寫的注釋,不對的地方大家評論指出
     @{            @*這個是把當前的路由值格式化並儲存到currentController這個變數中,這裡是格式化為Controller->Action這種格式的,如果你的導覽功能表所指向的路徑都是在一個Controller下面,那就完全可以省掉Controller  *@            var currentController = string.Format("[{0}->{1}]", ViewContext.RouteData.Values["controller"].ToString(), ViewContext.RouteData.Values["action"].ToString());        }        @*helper文法讓你可以輕鬆在視圖模板中建立可重用的協助方法,以此來封裝一些負責向頁面進行輸出的功能        這裡就是使用了Helper來構造了MenuItem這樣一個協助方法,來得到導覽功能表項的樣式*@        @helper MenuItem(string curControllerName, string allowedControlNames)        {        @(Html.Raw(allowedControlNames.IndexOf(curControllerName, StringComparison.InvariantCultureIgnoreCase) != -1 ? " TT3 " : ""))        }        <ul>            @*應用MenuItem協助方法,得到當前菜單的樣式*@            <li class="@MenuItem(currentController,"[Home->CompanyIntroduction]")"><a href="@Url.Action("Controller","Actioin")">菜單1</a></li>            <li class="@MenuItem(currentController, "[Lottery->Trends]") TT2"><a href="@Url.Action("Controller", "Action")">菜單2</a></li><li class="@MenuItem(currentController, "[Lottery->Trends]")"><a href="@Url.Action("Controller","Action")">菜單3</a></li>            <li class="@MenuItem(currentController, "[Lottery->Forecast]") TT2"><a href="@Url.Action("Controller","Action")">菜單4</a></li>        </ul>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.