문제

When i enable my BundleTable.EnableOptimizations in my mvc project for my javascript files it doesn't load any of the files. I'm not getting any errors as well. It simply won't load any of my files.

This is my bundle:

bundles.Add(new ScriptBundle("~/Content/javascripts").Include(
                    "~/Content/js/custom.js",
                    "~/Content/js/customizer.js",
                    "~/Content/js/main.js",
                    "~/Content/js/bootstrap.js",
                    "~/Content/js/jquery-ui-min.js",
                    "~/Content/js/bootstrap-switch-min.js"
                    ));

And in my view:

@Scripts.Render("~/Content/javascripts")

All the files do exist, because when i disable the optimizations it works fine again.

도움이 되었습니까?

해결책

It might be mistaking your virtual path ~/Content/javascripts for a real path. Try this instead.

bundles.Add(new ScriptBundle("~/bundles/javascripts").Include(
                "~/Content/js/custom.js",
                "~/Content/js/customizer.js",
                "~/Content/js/main.js",
                "~/Content/js/bootstrap.js",
                "~/Content/js/jquery-ui-min.js",
                "~/Content/js/bootstrap-switch-min.js"
                ));

And in your view.

@Scripts.Render("~/bundles/javascripts")

다른 팁

When you enable bundle Optimization in MVC it uses virtual folder the ~/Bundles/JQuery?v=xxxxx. in my case it was access denied (use F12 tool), because of this virtual folder "bundles" was not allow to access without login. I added bundles path to web config as:

  <location path="bundles">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

hope this helps

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top