【问题标题】:MVC 3 Rendering a section in a areaMVC 3渲染区域中的部分
【发布时间】:2011-10-24 13:31:44
【问题描述】:

我正在尝试从我的自定义区域呈现在 _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>

【问题讨论】:

  • 你能提供的任何代码都很好。

标签: asp.net-mvc-3 asp.net-mvc-3-areas


【解决方案1】:

在您的问题中,您指出了一个路径为 ~/Views/_layout.cshtml 的代码示例,并且在您所在区域下的 _ViewStart.cshtml 文件中,您具有以下代码:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

我相信你会在这里找到七个不同之处:)

七不同的东西是个笑话,但无论如何。您的 _Layout.cshtml 位于 ~/Views/ 下方,但您引用的 _Layout.cshtml 位于 ~/Views/Shared/ 下方。

【讨论】:

  • 七种区别?如果您的意思是 _layout.cshtml 和 _Layout.cshtml,我在更新问题时错过了输入。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 1970-01-01
  • 2011-03-22
相关资源
最近更新 更多