Bundling in MVC4

本文关键字:MVC4 in Bundling | 更新日期: 2023-09-27 18:07:03

在我的MVC应用程序中,最初我调用了每个页面中的所有脚本和样式。在看到捆绑概念之后。我参考了Bundle中的脚本和样式。配置页面。这里的脚本没有在我的页面中提及。我没有在我的应用程序中使用布局页面。

Bundle.config

    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{1.7.1}.js"));
    bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                "~/Scripts/jquery-ui-{1.8.20}.js"));
    bundles.Add(new ScriptBundle("~/bundles/jqueryuc").Include(
                "~/Scripts/jquery.dcmegamenu.1.3.3.js",
                "~/Scripts/jquery.hoverIntent.minified.js"));
    bundles.Add(new ScriptBundle("~/bundles/jqueryuh").Include(
                "~/Scripts/html5.js"));
    bundles.Add(new ScriptBundle("~/bundles/jqueryumin").Include(
                "~/Scripts/jquery.uniform.min.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryea").Include(
                "~/Scripts/jquery.easing.1.3.js",
                "~/Scripts/jquery.hoverIntent.minified.js"));
    bundles.Add(new StyleBundle("~/CSS/css").Include(
                "~/CSS/AdminLayStyle.css",
                "~/CSS/tab.css",
                "~/CSS/login.css", 
                "~/CSS/login-box.css",
                "~/CSS/base.css",
                "~/CSS/style_file.css",
                "~/CSS/menustyle.css"));
    bundles.Add(new StyleBundle("~/CSS/Content/themes/base/css").Include("~/CSS/Content/themes/base/jquery-ui.css",
                "~/CSS/Content/themes/base/jquery.ui.all.css",
                "~/CSS/Content/themes/base/jquery.ui.base.css",
                "~/CSS/Content/themes/base/jquery.ui.dialog.css",
                "~/CSS/Content/themes/base/jquery-ui.css", 
                "~/CSS/Content/themes/base/jquery.ui.theme.css"));

and in View Index.cshtml

 @Scripts.Render("~/bundles/jquery")
 @Scripts.Render("~/bundles/jqueryui")
 @Scripts.Render("~/bundles/jqueryuc")
 @Styles.Render("~/Content/css")

是对Bundle中样式的引用。配置正确吗??
提前感谢。
编辑:
是否有任何规则,所有的样式应该只引用从内容文件夹??

Bundling in MVC4

javascript看起来不错。CSS有问题。没有定义任何~/Content/css包。你的意思可能是:

@Styles.Render("~/CSS/css")

你可能还想包含jQuery UI样式:

@Styles.Render("~/CSS/Content/themes/base/css")

我明白了。引用样式和图像的相对路径必须来自Content文件夹