发布使用捆绑的MVC 4.0项目(<compilation debug =“false”targetframework =“4.0”>)</compilation>

时间:2013-07-20 01:20:42

标签: asp.net-mvc razor bundle

这是我的明星:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Bootstrap/assets/js/jquery.js"));

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                "~/Bootstrap/assets/js/bootstrap-transition.js",
                "~/Bootstrap/assets/js/bootstrap-alert.js",
                "~/Bootstrap/assets/js/bootstrap-modal.js",
                "~/Bootstrap/assets/js/bootstrap-dropdown.js",
                "~/Bootstrap/assets/js/bootstrap-scrollspy.js",
                "~/Bootstrap/assets/js/bootstrap-tab.js",
                "~/Bootstrap/assets/js/bootstrap-tooltip.js",
                "~/Bootstrap/assets/js/bootstrap-popover.js",
                "~/Bootstrap/assets/js/bootstrap-button.js",
                "~/Bootstrap/assets/js/bootstrap-collapse.js",
                "~/Bootstrap/assets/js/bootstrap-carousel.js",
                "~/Bootstrap/assets/js/bootstrap-typeahead.js",
                "~/Bootstrap/assets/js/bootstrap-affix.js",
                "~/Bootstrap/assets/js/application.js",
                "~/Bootstrap/assets/js/bootstrap.js"
                ));

}

以下是我的_Layout页面内容的一部分:

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

当我尝试运行此应用程序时,我得到的js错误看起来像这样

An Error has occurred in the script on this page
Object Expected
URL   http://servername/AppName/bundles/bootstrap?v=asdjisdjsincdjijadosJISJDIS_idosd 

这里提出了类似的问题: Why is my CSS bundling not working with a bin deployed MVC4 app?

我尝试将此配置添加到我的web.config文件中,如我所提到的那样引用

<modules runAllManagedModulesForAllRequests="true">
  <remove name="BundleModule" />
  <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>

我仍然遇到同样的错误。

如果不清楚,请告诉我,我会详细说明。 感谢

1 个答案:

答案 0 :(得分:0)

您的应用程序中是否存在Bundle文件夹?

尝试:

bundles.Add(new ScriptBundle("~/Bootstrap/assets/js/jquery").Include(
            "~/Bootstrap/assets/js/jquery.js"));

bundles.Add(new ScriptBundle("~/Bootstrap/assets/js/bootstrap").Include(

http://www.mvccentral.net/Story/Details/articles/kahanu/stylebundle-403-error-solved

MVC CSS not rendering in Visual Studio When debugging