MVC3引用了Layout页的View页面会有
@{
ViewBag.Title = "Test";
Layout = "~/Views/Shared/_Layout.cshtml";
}
Layout = "~/Views/Shared/_Layout.cshtml";这一行删除后,访问该view仍会引用该布局.
请问这是为什么?
还有就是引用了Layout的view怎么加自己的<style type="text/css"></style>??
View文件夹下面会有个_ViewStart.cshtml的文件,初始化了你的模板。如果不使用模板Layout = null
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
添加css可以按楼上说的
通常我会把CSS |RenderSection加在头,js加在末尾
<!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" /> }
谢谢!
@棋怜: 受教
Layout = "~/Views/Shared/_Layout.cshtml";
这是Layout的默认值。
在_Layout.cshtml添加:
@RenderSection("HeadCss", required: false)
在view中添加:
@section HeadCss{ <style type="text/css"> </style> }
谢谢!