代码改变世界

MVC3.0入门学习笔记-Razor 之样式加载方式2

2012-03-08 16:01  通心菜  阅读(549)  评论(0编辑  收藏  举报

上一篇简单的介绍了css js加载通用方法

_Layout.cshtml

<html>
<head>
<title>xx-用户中心</title>
@Style.Css("/css/globalv3.0.css", this.Url)
@Style.Css("/css/incv3.0.1.css", this.Url)
@Style.Css("/css/personal/memberv3.0.1.css", this.Url)
@Style.Script("/script/jquery.js", this.Url)
@Style.Script("/script/member.js", this.Url)
@if (IsSectionDefined("header")) //判断下子页面是否有这个属性
{
@RenderSection("header", true);//这个用Section这个特性起一个占位的作用 方便后面的子页面可以把自己的样式或者其他插入到这里

}
</head>


a.cshtm

@section header{
@Style.Css("/offerstyle/css/offer-manage.css", this.Url)
@Style.Script("/script/formValidator.js", this.Url)
@Style.Script("/script/formValidatorRegex.js", this.Url)
}

这样a.cshtm自己的样式就插到<head></head>中了