javascript - 网站未通过 bundle 加载 jQuery

标签 javascript c# jquery asp.net-mvc visual-studio-2013

我有一个 MVC5 中的应用程序,使用 c#、HTML 和 jQuery。

在我的本地主机中,一切正常,没有重大错误。但是,当我发布项目(右键单击项目 -> 发布)并将结果发送到公共(public)服务器时,我到处都出现加载错误:

enter image description here

我已经检查了生成的 ZIP 文件,并且 100% 所有 jQuery 文件都在其中,因此文件没有丢失。

此时我认为可能存在加载问题或其他问题,但我不知道可能是什么。是什么导致我的服务器无法加载 jQuery?

我的 Bundle.cs 文件:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui-{version}.js"));

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

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                    "~/Scripts/bootstrap.js",
                    "~/Scripts/bootstrap-datepicker.js",
                    "~/Scripts/bootstrap-editable.min.js",
                    "~/Scripts/bootstrap-editable.js",
                    "~/Scripts/bootstrap-switch.js",
                    "~/Scripts/select2.js",
                    "~/Scripts/bootstrapSwitch.js",
                    "~/Scripts/Amaris.XEditable.js",
                    "~/Scripts/bootstrap-modal.js",
                    "~/Scripts/AmarisFeedback.js",
                    "~/Scripts/bootstrap-modalmanager.js"));

        bundles.Add(new ScriptBundle("~/bundles/custom").Include(
            "~/Scripts/custom.js",
            "~/Scripts/fakeauth.js",
            "~/Scripts/jquery.dynatree.js",
            "~/Scripts/TableFilter.js",
            "~/Scripts/PackageScripts.js",
            "~/Scripts/MaterialScripts.js",
            "~/Scripts/PendingTableScripts.js",
            "~/Scripts/NotificationScripts.js"));

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

        //notfitications for all the family! http://www.jqueryrain.com/?sPi0WIEh
        bundles.Add(new ScriptBundle("~/bundles/notifIt").Include("~/Scripts/notifIt.js"));

这是我加载包的地方:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>@ViewBag.Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    @RenderSection("head", required: false)
    @RenderSection("head", required: false)
    @Styles.Render("~/Content/css")
</head>

<body>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/notifIt")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/custom")

    @RenderSection("scripts", required: false)
</body>

最佳答案

问题的根源在于 VisualStudio 本身。 在分析 VS 在发布项目时创建的 ZIP 文件(右键单击 -> 发布)后,我们注意到 ZIP 文件缺少 jQuery 库文件以及其他 JS 文件。

这些文件本应包含在解决方案中,但由于我们无法理解的原因,它们并未包含在内。

为了解决这个问题,我们必须手动从项目中删除受影响的文件(通过将它们复制到安全位置,然后在项目中删除它们),重新编译项目,然后再次添加文件(然后再次重新编译)。

通过这些步骤,VS 并未包含 ZIP 中的所有文件。最后。

关于javascript - 网站未通过 bundle 加载 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27857696/

相关文章:

javascript - 将动态验证文本添加到自定义 jQuery 验证规则

javascript - RequireJS 不加载依赖项

javascript - 如何使用jquery从文件输入类型获取文件名而不需要表单提交

c# - 需要有关从 C# 中的 Directory.GetFiles 方法中过滤掉某些文件名的好方法的建议

c# - 将图像转换为字节数组的问题

javascript - 使用 JQuery 更改表单操作

jquery - 清理简单的动画 jquery 代码

JavaScript 计算器 if 语句

javascript - elasticsearch-js库中的多字段搜索

c# - 如何在 .NET 中使用 perl 风格的替换表达式