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>