ASP.NET MVC 4 ScriptBundle returns empty

谁说我不能喝 提交于 2019-12-21 04:00:11

问题


Specifically, I am trying to create a ScriptBundle in MVC 4 with already minified scripts, and return this same Bundle whether the project is in Debug or not.

My web project references the MVC Telerik Grid NuGet package. In that package, Telerik only provides the minified JS files. Bundling code is below.

        // telerik scripts
        bundles.Add(new ScriptBundle("~/scripts/bundles/telerik").Include(
            "~/Scripts/2012.1.214/telerik.common.min.js",
            "~/Scripts/2012.1.214/telerik.textbox.min.js",
            "~/Scripts/2012.1.214/telerik.calendar.min.js",
            "~/Scripts/2012.1.214/telerik.datepicker.min.js",
            "~/Scripts/2012.1.214/telerik.grid.min.js",
            "~/Scripts/2012.1.214/telerik.grid.filtering.min.js"));

Other ScriptBundles run fine, but when my project attempts to reference this bundle, the request appears as: scripts/bundles/telerik?v= Returning nothing.

If I set BundleTable.EnableOptimizations = true, then it DOES return the ScriptBundle and references a specific version, however this solution is unacceptable.

I do not want to forcibly set BundleTable.EnableOptimizations = true, since I want all other Bundles to return the non-minified versions when appropriate.

Anyone have a similar experience and if so, what was the solution?


回答1:


I think you have the same problem, please look at this link: mvc4 bundler not including .min files

Either rename .min.js to .js or do something like:

    public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
    {
        if (ignoreList == null)
            throw new ArgumentNullException("ignoreList");

        ignoreList.Clear();

        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);
    }


来源:https://stackoverflow.com/questions/12569259/asp-net-mvc-4-scriptbundle-returns-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!