ASP.NET MVC 3 嵌套母版页 - 如何在 cshtml 视图中使用它?
我有这 2 个母版页 - Site.Master 和 Blog.Master 我想知道如何在我的 cshtml 视图中使用 Blog.Master?
Site.Master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="phPageTitle" runat="server" />
</title>
</head>
<body>
<div>
<div style="clear:both">
<asp:ContentPlaceHolder ID="phAppMenu" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div style="clear:both;min-height:500px">
<asp:ContentPlaceHolder ID="phContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div style="clear:both">
<asp:ContentPlaceHolder ID="phFooter" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</body>
</html>
这是 blog.master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" MasterPageFile="~/Views/Shared/Masters/Site.Master" %>
<asp:ContentPlaceHolder ID="iphPageTitle" ContentPlaceHolderID="phPageTitle" runat="server">
This is the page title
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphTopMenu" ContentPlaceHolderID="phTopMenu" runat="server">
Home | Browse | Search | Post | New | Featured | Recommended
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphContent" ContentPlaceHolderID="phContent" runat="server">
Main Content goes here
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphFooter" ContentPlaceHolderID="phFooter" runat="server">
This is the footer
</asp:ContentPlaceHolder>
这是我想在其中使用 Blog.Master 的 Post.cshtml:
@model MyApp.Models.ShowPostViewModel
@{
ViewBag.Title = Model.Post.Title;
}
<section>
<article>
<div style="overflow:hidden">
<div style="overflow:hidden">
<header>
<b>@Model.Post.Title</b><br />
Author: @Model.Post.Author | Id: @Model.Post._id
</header>
@Html.Raw(Model.Post.Content)
</div>
</div>
</article>
</section>
I have these 2 master pages - Site.Master and Blog.Master
I want to know how can I use the Blog.Master in my cshtml view?
Site.Master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="phPageTitle" runat="server" />
</title>
</head>
<body>
<div>
<div style="clear:both">
<asp:ContentPlaceHolder ID="phAppMenu" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div style="clear:both;min-height:500px">
<asp:ContentPlaceHolder ID="phContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div style="clear:both">
<asp:ContentPlaceHolder ID="phFooter" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</body>
</html>
Here is blog.master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" MasterPageFile="~/Views/Shared/Masters/Site.Master" %>
<asp:ContentPlaceHolder ID="iphPageTitle" ContentPlaceHolderID="phPageTitle" runat="server">
This is the page title
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphTopMenu" ContentPlaceHolderID="phTopMenu" runat="server">
Home | Browse | Search | Post | New | Featured | Recommended
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphContent" ContentPlaceHolderID="phContent" runat="server">
Main Content goes here
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="iphFooter" ContentPlaceHolderID="phFooter" runat="server">
This is the footer
</asp:ContentPlaceHolder>
Here is my Post.cshtml where I want to use the Blog.Master:
@model MyApp.Models.ShowPostViewModel
@{
ViewBag.Title = Model.Post.Title;
}
<section>
<article>
<div style="overflow:hidden">
<div style="overflow:hidden">
<header>
<b>@Model.Post.Title</b><br />
Author: @Model.Post.Author | Id: @Model.Post._id
</header>
@Html.Raw(Model.Post.Content)
</div>
</div>
</article>
</section>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不直接支持将 aspx master 与 razor 视图一起使用,但有一些解决方法。更多信息请参见:http://www.hanselman.com/blog/MishingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
Using an aspx master with a razor view is not directly supported, but there are workarounds. More info here: http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx