使用活动链接为NavBar设置样式

时间:2016-05-30 14:35:13

标签: html asp.net asp.net-mvc twitter-bootstrap

如何突出显示哪些活动项目Navbar

我尝试了一些示例,但是我无法更改“活动”样式以获得所需的查找。 这是我的_Layout.cshtml文件:

@{
    ViewBag.AppName = "My Application!";
}


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title @ViewBag.AppName</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid rtl" >
            <div class="navbar-header" style="float:right">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink((string)ViewBag.AppName, "Index", "Home", null, new { @class = "navbar-brand" })
            </div>
            @*<ul class="nav nav-tabs">
                <li>@Html.ActionLink("Home", "Index", "Home")</a></li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
            </ul>*@
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li class="active">@Html.ActionLink("Summary", "Index", "Home")</li>
                    <li>@Html.ActionLink("Request1", "Index", "PaymentRequest")</li>
                    <li>@Html.ActionLink("Request2", "Index", "CaptialPaymentRequest")</li>
                    <li>@Html.ActionLink("Request3", "Contact", "Home")</li>
                    <li>@Html.ActionLink("Request4", "Index", "Contract")</li>
                    <li>@Html.ActionLink("Request5", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

如果您发现我有以下测试线:

        <li class="active">@Html.ActionLink("Summary", "Index", "Home")</li>

其中突出显示摘要链接,但我希望如此:

1- MVC自动激活当前页面的链接

2-活动链接的样式更改(我在Site.css中的css下面使用了不起作用)

.navbar #nav > .active > a {
    color: red;
}

这是我的NavBar看起来像: enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个。

在ul

中添加id =“nav”
SELECT col.PathName() AS path FROM tbl

然后添加此脚本

<ul class="nav navbar-nav" id="nav">