捆绑脚本没有得到呈现 [英] Bundling scripts are not getting rendered

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

问题描述

我有脚本捆绑和缩小与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 code检查我发现状态code对上述资源状态code:302找到而对于脚本/ 状态code: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

而且我也无法通过点击它查看源代码访问的脚本文件,所以看起来好像没什么然而加载的所有文件和目录都理所当然地放置。
只为信息,我的样式表绑定工作正常。

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 目录

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

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