Home > Software design >  Bootstrap dropdown-toggle doesn't toggle
Bootstrap dropdown-toggle doesn't toggle

Time:12-09

I'm at my wits end. I started up a new ASP.Net core web app and am trying to add a simple menu with a dropdown. However, the dropdown won't toggle open.

(And when is stackoverflow going to remove the ridiculous "issue" of you need more content to match the amount of code you're posting. Sometimes a question is short! Thanks!)

The dropdown:

                        <li >
                        <a  data-toggle="dropdown" asp-area="">Json</a>
                        <span ></span></a>
                        <ul >
                            <li><a  asp-area="" asp-page="LoadJson">Load Json</a></li>
                            <li><a  asp-area="" asp-page="BulkLoadJson">Bulk Load Json</a></li>
                        </ul>
                    </li>

All the code in the page:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - DataMagnifierAdmin</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
    <link rel="stylesheet" href="~/DataMagnifier_Admin.styles.css" asp-append-version="true" />
</head>
<body>
    <header>
        <nav >
            <div >
                <a  asp-area="" asp-page="/Index">DataMagnifierAdmin</a>
                <button  type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span ></span>
                </button>
                <div >
                    <ul >
                        <li >
                            <a  asp-area="" asp-page="/Index">Home</a>
                        </li>
                        <li >
                            <a  asp-area="" asp-page="ExecETL">Execute ETL</a>
                        </li>
                        <li >
                            <a  data-toggle="dropdown" asp-area="">Json</a>
                            <span ></span></a>
                            <ul >
                                <li><a  asp-area="" asp-page="LoadJson">Load Json</a></li>
                                <li><a  asp-area="" asp-page="BulkLoadJson">Bulk Load Json</a></li>
                            </ul>
                        </li>
                        <li >
                            <a  asp-area="" asp-page="/Privacy">Privacy</a>
                        </li>
                    </ul>
                    <partial name="_LoginPartial" />
                </div>
            </div>
        </nav>
    </header>
    <div >
        <main role="main" >
            @RenderBody()
        </main>
    </div>

    <footer >
        <div >
            &copy; 2022 - DataMagnifier_Admin - <a asp-area="" asp-page="/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="~/js/site.js" asp-append-version="true"></script>

    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

CodePudding user response:

Change data-toggle="dropdown" (Bootstrap 4) to data-bs-toggle="dropdown" (Bootstrap 5).

See the snippet below.

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL jjXkk Q2h455rYXK/7HAuoJl 0I4" crossorigin="anonymous"></script>

<li >
  <a  data-bs-toggle="dropdown" asp-area="">Json</a>
  <span ></span>
  <ul >
    <li><a  asp-area="" asp-page="LoadJson">Load Json</a></li>
    <li><a  asp-area="" asp-page="BulkLoadJson">Bulk Load Json</a></li>
  </ul>
</li>

  • Related