Implementation of ASP.net MVC navigation label background color switching __.net

Source: Internet
Author: User

Effect: Site navigation A special effect is when located in different pages, the corresponding navigation of the label is highlighted, the background color deepened.

Solution: By setting an identity value in a different page, return to the _layout.cshtml layout page to set the CSS class for the corresponding navigation.

Specific implementation:

Method One

1, set the identity value in the index.cshtml, @{viewbag.navindex = 0;}.

2, receive the identity value in the _layout.cshtml and control the CSS class through JavaScript.

<script type= "Text/javascript" >
$ (function ()
{
var m = @ViewBag. Navindex
$ ("#navbar ul li"). EQ (m). addclass ("active");
});
</script>

Method Two

1, set the identity value in the index.cshtml, @{viewbag.tabindexclass = "Active";}

2, in the _layout.cshtml to receive the identity value, the HTML tag directly referenced. <li class= "@ViewBag. Tabindexclass" > @Html. ActionLink ("homepage", "index", "Home") </li>

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.