用剃刀MVC儿童主页 [英] MVC Child Master page with Razor
问题描述
我有一个旧的MVC2项目,我gradulately转换为MVC 5,用剃刀。
I have an old MVC2 project that I gradulately convert to MVC 5, with Razor.
与ASP母版页剃刀意见是不可能的,我决定复制的Site.Master
到 _Layout.cshtml
。
As the razor views with ASP Master Pages is not possible, I decided to duplicate the Site.Master
into _Layout.cshtml
.
一切正常,但不过有一个问题。
Everything is OK But there is a problem, however.
我有一个其他的母版页, TwoColumnsLayout.Master
,一种儿童母版页,是这样开始的:
I have an other Master page, TwoColumnsLayout.Master
, a kind of "child" master page, that begins like this:
<%@ Master MasterPageFile="~/Views/Shared/Site.Master" Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<asp:Content ContentPlaceHolderID="MetaContent" runat="server">
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<div class="breadcrumbs">
...
如何可能转换和使用这一个剃刀引擎?
How is possible to convert and use this one with the Razor engine?
推荐答案
利用 @ {布局=; }
功能。
例如:
〜/查看/共享/ _LayoutMain.cshtml
<html>
<head>
<link href="..." rel="stylesheet" type="text/css" />
</head>
<body>
<!-- header markup -->
@RenderBody()
<!-- footer markup -->
</body>
</html>
〜/查看/共享/ _LayoutChild.cshtml
@{
Layout = "~/Views/Shared/_LayoutMain.cshtml";
}
<!-- Child Layout content -->
<div>
@RenderBody()
</div>
〜/查看/我的页面/ _SomeViewPage.cshtml
@{
Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
<div>
@RenderBody()
</div>
这篇关于用剃刀MVC儿童主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!