MVC4中的Styles.Render
在.NET MVC4项目中, @Styles.Render是如何工作的?
我的意思是,在@Styles.Render("~/Content/css")中调用哪个文件?
我的Content文件夹中没有文件或名为“css”的文件夹。
它调用包含在App_Start文件夹中的BundleConfig类中声明的特定包中的文件。
在这种特殊情况下,对@Styles.Render("~/Content/css")的调用称为“〜/ Content / site.css”。
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
注意区分大小写。 如果你有一个文件
/Content/bootstrap.css
并将你的Bundle.config重定向到
.INCLUDE( “〜/内容/ Bootstrap.css”)
它不会加载CSS。
晚会晚了一点。 但似乎没有人提到过
捆绑和缩小StyleBundle ,所以..
@Styles.Render("~/Content/css")
在Application_Start()调用:
BundleConfig.RegisterBundles(BundleTable.Bundles);
反过来调用
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/Site.css"));
}
RegisterBundles()有效地结合& 缩小了 bootstrap.css和Site.css
成一个文件,
<link href="/Content/css?v=omEnf6XKhDfHpwdllcEwzSIFQajQQLOQweh_aX9VVWY1" rel="stylesheet">
但是 ..
<system.web>
<compilation debug="false" targetFramework="4.6.1" />
</system.web>
只有在Web.config中将debug设置为false 时才有效 。
否则, bootstrap.css和Site.css将单独提供。
不捆绑,也不缩小:
<link href="/Content/bootstrap.css" rel="stylesheet">
<link href="/Content/Site.css" rel="stylesheet">
链接地址: http://www.djcxy.com/p/67973.html
