View Code
@{
Layout = "~/Views/Shared/_Layout.cshtml"
}
添加css可以按楼上说的
通常我会把CSS |RenderSection加在头,js加在末尾
View Code
复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@RenderSection("Meta",false)
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
@RenderSection("Css",false)
</head>
<body>
@RenderBody()
@RenderSection("Js",false)
</body>
</html>
复制代码
在视图直接引用
@section Css{
<link href="@Url.Content("~/Content/AdminCss/Article.css")" rel="Stylesheet" type="text/css" />
}
不要用<script lang="javascript" scr="...."></script>的形式来写,RAZOR应该写成@Scripts.Render("~/Scripts/jquery.js"),这样就能避免路径改变或引用母板页而导致的连接失效问题css可以用原来的<link>方式,但一定要用“~/”来指定路径!例如:
<link href="~/Content/style.css" type="text/css" rel="stylesheet" />