Reputation: 28586
I have an old MVC2 project that I gradulately convert to MVC 5, with Razor.
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.
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?
Upvotes: 0
Views: 1957
Reputation: 7525
utilize @{ Layout = ""; }
feature.
For Example:
~/Views/Shared/_LayoutMain.cshtml:
<html>
<head>
<link href="..." rel="stylesheet" type="text/css" />
</head>
<body>
<!-- header markup -->
@RenderBody()
<!-- footer markup -->
</body>
</html>
~/Views/Shared/_LayoutChild.cshtml:
@{
Layout = "~/Views/Shared/_LayoutMain.cshtml";
}
<!-- Child Layout content -->
<div>
@RenderBody()
</div>
~/Views/MyPage/_SomeViewPage.cshtml:
@{
Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
<div>
@RenderBody()
</div>
Upvotes: 2
Reputation: 33306
You just need to use nested layout templates instead.
Create another layout _TwoColumnsLayout.cshtml
with the following:
@{
Layout = "~/Shared/_Layout.cshtml";
}
//Nested specific markup ...
@RenderBody()
Then in your view specify your new nested template as follows:
@{
Layout = "~/Shared/_TwoColumnsLayout.cshtml.cshtml";
}
Upvotes: 0