捆绑脚本未呈现 [英] Bundling scripts are not getting rendered

查看:35
本文介绍了捆绑脚本未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 ASP .NET 进行脚本捆绑和缩小时遇到问题我已经尝试了互联网上所有流行的解决方案,但仍然遇到同样的问题.

I am having a problem with script bundling and minification with ASP .NET I have tried all popular solution found on internet but still having the same problem.

我的 BundleConfig.cs 看起来像

namespace MYPROJ{
public class BundleConfig
{
    public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
    {
        if (ignoreList == null)
            return;
        ignoreList.Ignore("*.intellisense.js");
        ignoreList.Ignore("*-vsdoc.js");
        ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
        ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
        ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
    }

    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.IgnoreList.Clear();
        AddDefaultIgnorePatterns(bundles.IgnoreList);

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

…
…

        //bundles.Add(new ScriptBundle("~/Scripts").Include("~/Scripts/jquery.unobtrusive-ajax.min.js", "~/Scripts/kendoui/kendo.all.min.js", "~/Scripts/kendoui/kendo.combobox.min.js", "~/Scripts/kendoui/kendo.grid.min.js"));
        //bundles.Add(new ScriptBundle("~/Scripts").Include("~/Scripts/kendoui/kendo.all.min"));
        //bundles.Add(new ScriptBundle("~/Scripts").Include("~/Scripts/kendoui/kendo.combobox.min"));
        //bundles.Add(new ScriptBundle("~/Scripts").Include("~/Scripts/kendoui/kendo.grid.min.js"));            
        bundles.Add(new ScriptBundle("~/Scripts").IncludeDirectory("~/Scripts", "*.js").IncludeDirectory("~/Scripts/kendoui", "*.js"));

        ……
        BundleTable.EnableOptimizations = true;
    }
}
}

在主视图中:

@Scripts.Render("~/Scripts")

现在,当我跑步时,我得到了这个标签:

Now after all this when I runs I get this tag:

<script src="/Scripts?v=ZnxC8dcoc3fJ-hfKQHLiTe19PjJFHwPhwHPUncuBtzE1"></script>

在使用 chrome 代码检查器时,我发现上述资源的状态代码是 Status Code: 302 Found 而对于 Scripts/ 它是 Status代码:404 未找到

And upon using chrome code inspector I found out that the status code for the above resource is Status Code: 302 Found And for Scripts/ it is Status Code: 404 Not Found

而且我也无法通过在视图源中单击来访问脚本文件,因此看起来没有加载任何内容,但是所有文件和目录都正确放置.仅供参考,我的 styleSheets 捆绑工作正常.

And I also cannot access the script file by clicking it in the view source, so looks like nothing is loaded however all files and directories are rightly placed. Just for the info, my styleSheets bundling is working fine.

请帮忙谢谢.

推荐答案

你不能给你的包的名称同时也是现有目录的名称.重命名包或添加 /js 以使其正常工作:

You can't give your bundle a name that is also the name of an existing directory. Rename the bundle or add a /js to make it work correctly:

bundles.Add(new ScriptBundle("~/Scripts/js").IncludeDirectory("~/Scripts", "*.js").IncludeDirectory("~/Scripts/kendoui", "*.js"));

@Scripts.Render("~/Scripts/js")

不存在的任何其他名称也可以使用,例如

Any other name that doesn't exist would work as well, e.g.

 bundles.Add(new ScriptBundle("~/ScriptMonkey").IncludeDirectory("~/Scripts", "*.js").IncludeDirectory("~/Scripts/kendoui", "*.js"));

...假设您没有 /ScriptMonkey 目录.

...assuming you don't have /ScriptMonkey directory.

这篇关于捆绑脚本未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆