一、配置BundleConfig.cs文件
1、首先要在App_Start 里面BundleConfig.cs 文件里面 添加要包含的css文件
2、BundleConfig就是一个微软新加的 一个打包的配置类
3、BundleConfig用来Add 各种Bundle
4、BundleConfig配置信息如下:
public class BundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new StyleBundle("~/Content1/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content1/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
二、使用Scripts.Render、Styles.Render引用BundleConfig中的配置
1、在视图文件中使用Scripts.Render()输出脚本包,Styles.Render()输出样式包
2、Script文件引用:@Scripts.Render(virtualPath[,virtualPath1][,virtualPath2][,...])
3、CSS文件引用: @Styles.Render(virtualPath[,virtualPath1][,virtualPath2][,...])
4、实例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content1/css")
</head>
<body>
@RenderBody()
@Scripts.Render("~/bundles/jqueryui")
</body>
</html>