【问题标题】:asp.net bundler "webpage/content/js" not found未找到 asp.net 捆绑程序“网页/内容/js”
【发布时间】:2023-03-25 18:58:02
【问题描述】:

我刚刚浏览了大量的谷歌页面来解决这个问题,但看起来每个页面都是独一无二的。我的页面源代码显示包以它应该工作的方式捆绑在一起

 <script src="/Content/js?v=N2f3Y-Z24wBpC67A34qPxjK1CR3eY83Yijs13VtHOwI1"></script>

,但是浏览器(chrome)开发工具提示加载失败:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:53608/Content/js/

而且,如果我也单击脚本 src 链接,我还会收到 microsoft 生成的消息,即资源丢失或找不到。

我可以加载其他捆绑包(样式),我想,我在代码布局中遗漏了一些东西,我自己找不到问题。如果你们中的任何人能指出我的错误,我将非常感激,所以这里是代码:

_Layout.cshtml

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/Content/js")
    @Scripts.Render("~/bundles/jquery")

BundleConfig.cs

            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-1.9.1.js",//(tried other numbers as well)
                    "~/Scripts/jquery-ui-1.10.4.js",
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*",
                    "~/Scripts/modernizr-*",
                    "~/Scripts/itpoverlay.js"
                    ));

        bundles.Add(new StyleBundle("~/Content/css").
            Include("~/Content/bootstrap.css",
            //"~/Content/ie.css",
            "~/Content/kwicks-slider.css",
            "~/Content/style.css",
            "~/Content/custom.css",
            "~/Content/responsive.css",
            "~/Content/touchTouch.css"));

        bundles.Add(new ScriptBundle("~/Content/js").Include(
          "~/Content/js/bootstrap.js",
          "~/Content/js/forms.js",
          "~/Content/js/jquery.easing.1.3.js",
          "~/Content/js/jquery.flexslider-min.js",
          "~/Content/js/jquery.kwicks-1.5.1.js",
          "~/Content/js/jquery.preloader.js",
          "~/Content/js/superfish.js",
          "~/Content/js/jquery.js",//(default bundle v1.8.1)
          "~/Content/js/touchTouch.jquery.js"));
       BundleTable.EnableOptimizations = true;

_references.js(我真的不知道它为什么在那里)

/// <reference path="jquery-1.9.1.js" />
/// <reference path="jquery-ui-1.10.4.js" />
/// <reference path="jquery.unobtrusive-ajax.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="jquery.validate.unobtrusive.js" />
/// <reference path="knockout-2.1.0.debug.js" />
/// <reference path="modernizr-2.5.3.js" />

现在对于输出,包看起来生成良好:

    <link href="/Content/css?v=NASaW-JeM0CkSMQIcoasDpn9k7bKaEK07c7WakA1Y0k1" rel="stylesheet"/>
    <script src="/Content/js?v=N2f3Y-Z24wBpC67A34qPxjK1CR3eY83Yijs13VtHOwI1"></script>
    <script src="/bundles/jquery?v=VwkJeyosUZnIv9pTtkEir1OOQCcR7BXo1RW8kdleacU1"></script>

并且开发工具标记了错误列表(我想,我开始了解 _reference.js 可能用于什么)是否也应该捆绑它?错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:53608/Content/js/
Uncaught TypeError: Object [object Object] has no method 'live' jquery?v=VwkJeyosUZnIv9pTtkEir1OOQCcR7BXo1RW8kdleacU1:1
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:53608/js/jquery.preloader.js

我希望它足以发现我的错误,如果有不清楚的地方,我很乐意用所需的信息更新问题。 谢谢,厄尼斯。

【问题讨论】:

    标签: javascript asp.net c#-4.0 razor bundles


    【解决方案1】:

    Jquery live 方法在 1.7 中已弃用,看起来您正在使用 1.9

    https://api.jquery.com/live/
    

    所以看起来你有两个选择。找出你在哪里使用 live 方法,并将其更改为使用 .on()。我不能给你具体的代码,因为我不知道你是如何使用 .live()

    或考虑使用 jquery migrate

    http://blog.jquery.com/2013/05/08/jquery-migrate-1-2-1-released/
    

    【讨论】:

    • 感谢您的注意,我想就是这样,但是 .live 用于 jquery.unobtrusive-ajax.js jquery.flexslider-min i> 这是构建我的网站的模板项目中包含的默认 sripts,加载器覆盖永远不会消失,这就是问题所在,所以只有迁移解决方案仍然正确?
    • Jup 迁移有帮助,我也通过使用 scriptsbundle.includeDirecotory("~/content/js","*.js") 解决了 content/js 发现的问题 非常感谢你,我真的想问题出在其他地方。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 2016-11-17
    • 2019-07-11
    • 2014-05-06
    • 2019-09-01
    相关资源
    最近更新 更多