我尝试为我的应用程序捆绑脚本和样式 Bootstrap 。我的调试正常,但是当我发布它时,不加载脚本和样式。
我添加一个 BundleConfig (BootstrapBundleConfig)
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/js").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-1.10.4.custom.js",
"~/Scripts/jquery-migrate-{version}.js",
"~/Scripts/bootstrap.js",
"~/Scripts/gridmvc.js",
"~/Scripts/gridmvc.lang.fa.js",
"~/Scripts/jquery.validate.js",
"~/scripts/jquery.validate.unobtrusive.js",
"~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js",
"~/scripts/entitypicker.js",
"~/scripts/js-persian-cal.js",
"~/scripts/json2.js",
"~/scripts/bootbox.js",
"~/Scripts/jalali.js",
"~/Scripts/calendar.js",
"~/Scripts/calendar-setup.js",
"~/Scripts/lang/calendar-fa.js"
));
bundles.Add(new StyleBundle("~/content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-responsive.css",
"~/Content/bootstrap-mvc-validation.css",
"~/Content/themes/ui-lightness/jquery-ui.css",
"~/Content/js-persian-cal.css",
"~/Content/entitypicker.css",
"~/Content/gridmvc.css",
"~/Content/aqua/theme.css",
"~/Content/calendar-system.css"
));
}
在全局中添加注册
BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
并在_layaout中设置样式/脚本
<link href="@Styles.Url("~/content/css")" rel="stylesheet" />
@Scripts.Render("~/js")
但是发布时,并打开查看页面源
<link href="/Content/css?v=65vDyivXbF9ucPBBLls9CVnwUcCNass7hOMNUEXbN-I1" rel="stylesheet" />
打开此文件时,第一行出现错误。
/* Minification failed. Returning unminified contents.
(962,1): run-time error CSS1019: Unexpected token, found '@charset'
(962,10): run-time error CSS1019: Unexpected token, found '"UTF-8"'
(962,17): run-time error CSS1019: Unexpected token, found ';'
(994,1): run-time error CSS1019: Unexpected token, found '@-webkit-keyframes'
我在Google中搜索并使用了不同的方法,但错误并未解决。
将所有样式添加到特殊路径(Content/Them/Bootstrap)并使用
new StyleBundle("~/content/Them/Bootstrap")
使用
BundleTable.EnableOptimizations = true;
其他..
最佳答案
如果您的 css 文件格式不正确,通常会发生这种情况,请使用 http://csslint.net/ 将您的 css 代码进行测试.
也不要使用这一行
<link href="@Styles.Url("~/content/css")" rel="stylesheet" />
你可以使用这个
@Styles.Render("~/content/css")
如果您想在不发布的情况下进行调试,您可以将此行添加到 BundleConfig
的 RegisterBundles
方法中:
BundleTable.EnableOptimizations = true;
关于asp.net-mvc - 与 MVC4.5 捆绑在发布后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24751124/