MVC navigation menu Highlighting implementation ideas

Source: Internet
Author: User

The code is not written by me, but has been personally tested, according to my understanding of the comments written, the wrong place everyone commented that
@{@* This is to format the current route value and save it to the Currentcontroller variable, which is formatted as controller->action, if your navigation menu points to a path that is in a cont Under Roller, it is entirely possible to dispense controller *@ var currentcontroller = string. Format ("[{0}->{1}]", viewcontext.routedata.values["Controller"]. ToString (), viewcontext.routedata.values["action"].        ToString ());        The @*helper syntax allows you to easily create reusable helper methods in a view template to encapsulate some of the functions that are responsible for outputting to the page here is a helper to construct a helper method to get the style of the navigation menu item *@ @helper MenuItem (String curcontrollername, String allowedcontrolnames) {@ (Html.raw (allowedcontrolnames.in Dexof (Curcontrollername, stringcomparison.invariantcultureignorecase)! =-1? "TT3": "))}<ul>@* Apply the MenuItem Help method to get the style of the current menu *@<Liclass= "@MenuItem (Currentcontroller,"[home->Companyintroduction] "><ahref= "@Url. Action ("Controller "," Actioin ")">Menu 1</a></Li>            <Liclass= "@MenuItem (Currentcontroller,"[lottery->Trends] "TT2" ><ahref= "@Url. Action ("Controller "," Action ")">Menu 2</a></Li><binclass= "@MenuItem (Currentcontroller,"[lottery->Trends] "><ahref= "@Url. Action ("Controller "," Action ")"> Menu 3</a></Li>            <binclass= "@MenuItem (Currentcontroller,"[lottery->Forecast] "TT2" ><ahref= "@Url. Action ("Controller "," Action ")"> Menu 4</a></Li>        </ul>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.