我如何修改母版页以修复asp.net中的Bootstrap4下拉菜单? (未捕获的TypeError:Bootstrap下拉列表需要Popper.js)

时间:2018-08-29 09:26:53

标签: javascript asp.net webforms bootstrap-4 popper.js

亲爱的,亲爱的,我尝试在更新到引导程序4之后在项目中使用下拉列表,它在更新之前可以工作,但在更新之后却无法正常工作,无论如何,在js中出现了以下错误,当我尝试单击下拉列表按钮时。

Uncaught TypeError: Bootstrap dropdown require Popper.js (https://popper.js.org)
    at Dropdown.toggle (bootstrap.js:1533)
    at HTMLButtonElement.<anonymous> (bootstrap.js:1690)
    at Function.each (jquery-3.0.0.js:359)
    at jQuery.fn.init.each (jquery-3.0.0.js:152)
    at jQuery.fn.init._jQueryInterface [as dropdown] (bootstrap.js:1675)
    at HTMLButtonElement.<anonymous> (bootstrap.js:1842)
    at HTMLDocument.dispatch (jquery-3.0.0.js:5087)
    at HTMLDocument.elemData.handle (jquery-3.0.0.js:4895)

为了解决这个问题,我进行了很多搜索,我尝试将umd中的popper.js以及直接链接到母版页或同一页面中的链接包括进来,但这不起作用

我也试图更改cssClass,但是什么也没发生。

这是我的母版页(Visual Studio默认添加)

<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %> - Arabian Food Supplies</title>

    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>
    <webopt:BundleReference runat="server" Path="~/Content/css" />
    <link href="Content/fontawesome-all.css" rel="stylesheet" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

    <style type="text/css">
        .auto-style1 {
            font-size: small;
            color: #999999;
        }
    </style>


</head>
<body>
    <form runat="server">
        <asp:ScriptManager runat="server" EnablePageMethods="true" EnableCdn="True">
            <Scripts>
                <%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
                <%--Framework Scripts--%>
                <asp:ScriptReference Name="MsAjaxBundle" />
                <asp:ScriptReference Name="jquery" />
                <asp:ScriptReference Name="bootstrap" />
                <asp:ScriptReference Name="respond" />                
                <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
                <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
                <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
                <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
                <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
                <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
                <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
                <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
                <asp:ScriptReference Name="WebFormsBundle" />
                <%--Site Scripts--%>
            </Scripts>
        </asp:ScriptManager>

第一次尝试:

    <div class="btn-group" role="group">
        <button id="btnGroupDrop1" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
        <ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
            <li>
                <asp:LinkButton ID="LinkButton2" runat="server">Solve</asp:LinkButton></li>
            <li>
                <asp:LinkButton ID="LinkButton3" runat="server">Abort</asp:LinkButton></li>
        </ul>
    </div>

第二次尝试

           <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
                Action<span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <li><a href="#">Solve</a></li>
                <li><a href="#">Abort</a></li>
            </ul>
        </div>

2 个答案:

答案 0 :(得分:0)

只需将CDN用于引导程序4或仅将popper.js添加到您的网页

用于引导程序4的CDN Lin:<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

下载链接到popper.js https://github.com/FezVrasta/popper.js/releases

答案 1 :(得分:0)

我找到了解决方法:

首先在Visual Studio中转到   Tools > NuGet Package Manager > Manage NuGet Packages for Solution 然后在已安装标签上,然后卸载AspNet.ScriptManager.bootstrab 之后卸载Bootstrap

下一步:在ScriptManager标签的Site.Master中,删除行<asp:ScriptReference Name="bootstrap" />

并将以下链接添加到母版页的 head标签

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>