如何在导航栏上使用Bootstrap?

gfttwv5a  于 12个月前  发布在  Bootstrap
关注(0)|答案(1)|浏览(161)
  • 它是ASP.NET的核心应用程序
  • 我使用的是Bootstrap 5,安装了lib manager -根据文档引用了必要的引导文件
<environment include="Development">
    <link href="~/lib/twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />

    <script src="~/lib/jquery/jquery.js"></script>
    <script src="~/lib/jquery-validate/jquery.validate.js"></script>
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js</script>

    <script src="~/lib/twitter-bootstrap/js/bootstrap.bundle.js"></script>
    <script src="~/lib/twitter-bootstrap/js/bootstrap.js"></script>
</environment>

字符串

  • 导航栏位于_Layout.cshtml文件中,其中是一个导航项列表,我希望其中一个导航项是一个子菜单
<li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle"
       data-bs-toggle="dropdown" aria-expanded="false">
        Manage
    </a>
    <ul class="dropdown-menu">
        <li>
            <a class="dropdown-item" asp-controller="Administration"
               asp-action="ListUsers">Users</a>
        </li>
        <li>
            <a class="dropdown-item" asp-controller="Administration"
               asp-action="ListRoles">Roles</a>
        </li>
    </ul>
</li>

  • 导航链接显示在浏览器上,但它是不可点击的,并不显示搜索项。任何帮助将不胜感激,谢谢。
zlhcx6iw

zlhcx6iw1#

您的html代码运行正常。请确保添加正确的版本 Bootstrap (在打开wwwroot\lib\bootstrap\dist\css\bootstrap.csswwwroot\lib\bootstrap\dist\js\bootstrap.js文件时检查文件的第一行)。
或者你可以使用cdnjs参考。整个HTML代码如下所示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - TestMVC</title>
    @* <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> *@
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.1/css/bootstrap.min.css" integrity="sha512-6KY5s6UI5J7SVYuZB4S/CZMyPylqyyNZco376NM2Z8Sb8OxEdp02e1jkKk/wZxIEmjQ6DRCEBhni+gpr9c4tvA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div class="container">
                <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">TestMVC</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">                   
                    <ul class="navbar-nav flex-grow-1">                       
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle"
                               data-bs-toggle="dropdown" aria-expanded="false">
                                Manage
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a class="dropdown-item" asp-controller="Administration"
                                       asp-action="ListUsers">Users</a>
                                </li>
                                <li>
                                    <a class="dropdown-item" asp-controller="Administration"
                                       asp-action="ListRoles">Roles</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                    
                </div>
            </div>
        </nav>
    </header>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2023 - TestMVC - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    @* <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> *@
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.1/js/bootstrap.min.js" integrity="sha512-ewfXo9Gq53e1q1+WDTjaHAGZ8UvCWq0eXONhwDuIoaH8xz2r96uoAYaQCm1oQhnBfRXrvJztNXFsTloJfgbL5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

    <script src="~/js/site.js" asp-append-version="true"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

字符串
结果显示:


的数据

相关问题