无法在ASP.NET中使Bootstrap下拉菜单正常工作。

huangapple go评论62阅读模式
英文:

Can't get the bootstrap dropdown working in ASP.NET

问题

我尝试在我的ASP.NET Core应用程序中创建一个下拉菜单。

下拉菜单的代码直接来源于getbootstrap.com:

<li class="nav-item">
    <div class="dropdown">
        <button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
            Dropdown button
        </button>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
        </div>
   </div>
</li>

但我只得到一个带有下拉箭头的按钮,根本无法使用。

我尝试按照这个stackoverflow问题中提供的解决方案,但也没有效果。
当前按钮的状态

我使用的是默认的样式表和JavaScript,根据getbootstrap.com应该足够了:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - HellBotWebUI</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="~/HellBotWebUI.styles.css" asp-append-version="true" />
</head>
<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>
英文:

I am trying to create a dropdown in my ASP.NET Core Application.

The code for my dropdown origintes directly from getbootstrap.com:

<li class="nav-item">
    <div class="dropdown">
        <button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
            Dropdown button
        </button>
        <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
        </div>
   </div>
</li>

But all i get is a button with the dropdown arrow that isn't working at all.

I tried following the solution provided in this stackoverflow question, but that also didn't work.
The button in its current state

I am using the default stylesheets and javascripts, which should be enough according to getbootstrap.com:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - HellBotWebUI</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="~/HellBotWebUI.styles.css" asp-append-version="true" />
</head>
<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>

答案1

得分: 2

ASP.NET Core web应用模板默认使用Bootstrap v5.1.0,因此您需要查看更新的文档

英文:

The ASP.NET Core web application templates use Bootstrap v5.1.0 by default so you need to look at the newer docs.

huangapple
  • 本文由 发表于 2023年4月19日 19:00:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053709.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定