asp.net - 在 Visual Studio 2017 ASP.NET MVC 中引导之前,Popper 未加载

标签 asp.net asp.net-mvc bundling-and-minification popper.js

我正在尝试实现弹出窗口,但似乎 poppers.js 不想在 bootstrap.js 之前加载。我尝试将 bundle 放在 Bootstrap bundle 之前,但它不想加载。 捆绑配置:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*"));

    // Use the development version of Modernizr to develop with and learn from. Then, when you're
    // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));

    bundles.Add(new ScriptBundle("~/bundles/popper").Include(
              "~/Scripts/popper.js"
              ));

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
              "~/Scripts/bootstrap.js"
              ));

    bundles.Add(new StyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.css",
              "~/Content/xbbcode.css",
              "~/Content/site.css"));


}

_布局:

@Scripts.Render("~/bundles/popper")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

我仍然收到此错误:

jQuery.Deferred exception: Bootstrap's tooltips require Popper.js (https://popper.js.org/) Tooltip@http://localhost:56609/Scripts/bootstrap.js:2836:15 Popover@http://localhost:56609/Scripts/bootstrap.js:3509:14 _jQueryInterface/<@http://localhost:56609/Scripts/bootstrap.js:3569:18 each@http://localhost:56609/Scripts/jquery-3.3.1.js:354:10 each@http://localhost:56609/Scripts/jquery-3.3.1.js:189:10 _jQueryInterface@http://localhost:56609/Scripts/bootstrap.js:3559:14 load/http://localhost:56609/:299:46 mightThrow@http://localhost:56609/Scripts/jquery-3.3.1.js:3534:21 resolve/http://localhost:56609/Scripts/jquery-3.3.1.js:3602:12 undefined jquery-3.3.1.js:3818:3 TypeError: Bootstrap's tooltips require Popper.js (https://popper.js.org/)

最佳答案

这个问题困扰了我大约 30 分钟,但我设法解决了它。我所做的只是添加 popper.js 的 UMD 版本,并将其与 bootstrap.js 捆绑在一起。

什么是UMD

The UMD pattern typically attempts to offer compatibility with the most popular script loaders of the day (e.g RequireJS amongst others). In many cases it uses AMD as a base, with special-casing added to handle CommonJS compatibility.

所以你的BundleConfig.cs看起来像这样......

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
            "~/Scripts/umd/popper.js",
            "~/Scripts/bootstrap.js"));

我还尝试将其单独捆绑,并且成功了。

        bundles.Add(new ScriptBundle("~/bundles/popper").Include(
                    "~/Scripts/umd/popper.js"));

记住将其添加到您的_Layout.cshtml中。另外,我认为顺序很重要,所以请尝试这个顺序。

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/popper")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)

所以首先是jQuerypopper,然后是bootstrap。希望这有帮助

关于asp.net - 在 Visual Studio 2017 ASP.NET MVC 中引导之前,Popper 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54893743/

相关文章:

c# - .Net 4.0 在使用 Attributes.Add 时编码单引号

c# - 如何使文本框自动完成结果选择直接导航到记录详细信息?

asp.net-mvc - MVC WebGrid 设置呈现的ID

asp.net-mvc-4 - 如何配置 MVC 的样式捆绑顺序?

ASP.NET MVC4 与 Twitter Bootstrap 捆绑

.net - 了解为 Umbraco 添加/创建新模板的基础知识

asp.net - ASPX中的设计 View 无法加载

asp.net - 没有表单标签的 RegisterClientScriptBlock

c# - 如何使用 asp.net 标识创建事务?

javascript - VS2013 - Web Essentials - "Update All Bundles"不工作