Mat*_*ira 5 layout asp.net-mvc-3
我找不到使 @section 和 @RenderSection() 使用多级布局的方法。在我的项目中,我定义了布局的层次结构:
〜/ Views / Shared / _Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta ... />
<meta ... />
<link href="..." rel="stylesheet" type="text/css" />
<link href="..." rel="stylesheet" type="text/css" />
@RenderSection("Stylesheet", false)
</head>
<body>
<!-- lots of markup -->
@RenderBody()
<!-- more markup -->
<script src="..." type="text/javascript" />
<script src="..." type="text/javascript" />
@RenderSection("JavaScript", false)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
~/Views/Shared/_BaseLayout.cshtml(没有 JavaScript 或样式表部分的定义):
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!-- lots of markup -->
@RenderBody()
Run Code Online (Sandbox Code Playgroud)
~/Views/Shared/_CreateEditLayout.cshtml(同样,没有 JavaScript 或样式表的定义):
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!-- lots of markup -->
@RenderBody()
Run Code Online (Sandbox Code Playgroud)
〜视图/配置文件/Edit.cshtml:
@model ...
@{
Layout = "~/Views/Shared/_CreateEditLayout.cshtml";
}
@section JavaScript {
<script type="text/javascript">
jQuery(document).ready(function ($) {
// lots of funny JS
});
</script>
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,只需定义@section JavaScript { }(无需在该部分内编写标记或 JavaScript)即可Edit.cshtml渲染我的站点。错误如下:已定义以下部分,但尚未为布局页面“~/Views/Shared/_CreateEditLayout.cshtml”呈现:“JavaScript”。
有什么想法出了什么问题吗?提前致谢。