asp.net-mvc – 在嵌套内容的区域上使用_ViewStart
我有一个_ViewStart定义我的项目的主布局(页眉,页脚).
在这个项目中,我有几个领域.每个区域都有相同的页眉和页脚,以及自己的侧面菜单.为此,我在该区域的根目录上创建了一个_ViewStart.这是(简化)代码: /Views/_ViewStart.cshtml @{ Layout = "~/Views/Shared/_Layout.cshtml"; } /Views/Shared/_Layout.cshtml <html> <div> //header </div> <div> @RenderBody </div> </html> 区域Foo – > /Areas/Foo/Views/_ViewStart.cshtml @{ Layout = "~/Views/Shared/_Layout.cshtml"; } <div class="row"> <div class="sidemenu"> //default sidemenu for this area </div> <div> @RenderBody() </div> </div> 页面/Areas/Foo/Views/Bar/Index.cshtml将无法呈现,我收到此错误: CS0103:当前上下文中不存在名称“RenderBody” 如何实现这种母版嵌套? 解决方法
我讨厌回答我自己的问题,但在这里:
如果您想在那里使用RenderBody,则无法直接在您所在区域的_ViewStart上引用网站的根_ViewStart. 所以解决方案是: /Views/_ViewStart.cshtml引用/Views/Shared/_MainLayout.cshtml /Areas/Foo/Views/_ViewStart.cshtml参考/Areas/Foo/Views/Shared/_AreaLayout.cshtml /Areas/Foo/Views/Shared/_AreaLayout.cshtml参考/Views/Shared/_MainLayout.cshtml 就是这样.您必须使用“共享”文件夹才能使用“RenderBody()”方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – Windows EventLog不能超过32766个字符
- ASP.NET Web Pages - WebMail 帮助器
- Asp.Net Identity发现用户不在角色中
- asp.net-core – 来自带有Entity Framework Core的Data Tie
- asp.net – Server.Transfer throws执行子请求时出错 如何解
- asp.net-mvc – ASP.NET MVC RadioButtonListFor始终是预设
- asp.net – 如何避免UpdatePanel在AutoPostBack上滚动?
- asp.net-mvc – 将参数传递给html partial并在部分html中检
- asp.net – 将tracelistener添加到web.config
- asp.net – 在.aspx主页中包含内容
- asp.net-mvc-4 – Durandal.js:更改每个区域的导
- asp.net – 组合两个List(Of String)最有效的方法
- asp.net – 如何处理从“DBNull”类型到“String
- asp.net-mvc-4 – URL以’/’结尾时的服务器错误
- asp.net – 无法打开登录请求的数据库.登录失败.
- asp.net – Handles子句需要在包含类型或其基类型
- asp.net – System.Web.Cache,会话级别或应用程序
- 当使用ASP.Net Membership和另外一个表来存储用户
- object – 经典ASP – 何时关闭记录集
- Asp.net超链接控件相当于