如何:区域中的嵌套布局?

时间:2012-08-03 09:55:30

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

我有一个遵循这种结构的ASP .NET MVC3(razor)站点:

Site1
    -Areas
        -Area1
            -Views
                -SomeFeature
                    -Index.cshtml --> sets the section 'pageScripts'
                -Shared
                    -_Layout.cshtml --> has Layout = ~/Views/Shared_Layout.cshtml, sets the section 'layoutScripts'

            -Viewstart.cshtml ---> has Layout = ~/Areas/Area1/Views/Shared/_Layout.cshtml

        -Area2
            -Views
                -Shared
    -Views
        -Shared
            -_Layout.cshtml ---> has optional sections pageScripts, layoutScripts

这是我的问题:

当我尝试访问~/Area1/SomeFeature/Index的等效控制器方法时,我收到一条异常消息说

The following sections have been defined but have not been rendered for the layout page "~/Areas/Area1/Views/Shared/_Layout.cshtml": "pageScripts".

我将“pageScripts”部分定义为

@RenderSection("pageScripts", false) in ~/Views/Shared_Layout.cshtml

为什么我要这样做:

目前,我发现自己必须将Area1(和Area2)中每个视图中的Layout属性设置为~/Views/Shared/_Layout.cshtml

有人知道我做错了吗?

- 感谢任何建议

1 个答案:

答案 0 :(得分:0)

只是在黑暗中拍摄。

1。)确保你使用_ViewStart,需要下划线;)。

2.确保_ViewStart位于Area中的Views文件夹中,而不是Area1文件夹中。至少那就是它在你的描绘中的样子。

希望其中一条建议可以解决问题。我使用类似的技术,工作得很好。

干杯,

涡流

相关问题