MVC 3 渲染区域中的一部分
我正在尝试从自定义区域渲染 _layout 文件中定义的部分。
在我的区域中,我有 _ViewStart ,它指向根站点中的 _layout 。
我尝试使用的部分位于 head 标签中,但在我的区域中,它被放在 body 中。
在根级别呈现的页面工作正常。
〜/ Views / Shared / _Layout.cshtml〜
<head>
@RenderSection("header", true)
</head>
<body>
....
</body>
/ Areas / UserMedia / Views / _ViewStart.cshtml〜
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
/ Areas / UserMedia / Views / ManageProjectMedia.cshtml
@{
ViewBag.Title = "ManageProjectMedia";
}
@section header{
{
<!-- scripts and styles -->
}
<div>
... page content
</div>
I am trying to render a section that is defined in _layout file from my custom area.
In my area I have the _ViewStart which points to the _layout in the root site.
The section that I am trying to use is in the head tag, but in my area it is put in the body.
Page that are rendered at the root level work fine.
~/Views/Shared/_Layout.cshtml
<head>
@RenderSection("header", true)
</head>
<body>
....
</body>
~/Areas/UserMedia/Views/_ViewStart.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
~/Areas/UserMedia/Views/ManageProjectMedia.cshtml
@{
ViewBag.Title = "ManageProjectMedia";
}
@section header{
{
<!-- scripts and styles -->
}
<div>
... page content
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于您的问题,您指出了一个代码示例,其路径为
~/Views/_layout.cshtml
并且在您所在区域下的 _ViewStart.cshtml 文件中,您有以下代码:我确信您会在这里找到七个不同:)七个不同的事情是一个笑话,但无论如何。您的
_Layout.cshtml
位于~/Views/
下,但您引用的是~/Views/ 下的
。_Layout.cshtml
共享/On your question you pointed out a code sample whose path is
~/Views/_layout.cshtml
and on your _ViewStart.cshtml file under your area, you have the following code :I am sure you will find the seven difference here :)Seven difference thing was a joke but anyway. Your
_Layout.cshtml
is sitting under~/Views/
but you're referencing_Layout.cshtml
which is under~/Views/Shared/
.