我想知道MVC框架是否可以利用嵌套母版页?如果有的话,是否有人知道如何实现这一目标?
答案 0 :(得分:40)
我们经常使用嵌套母版页,以便从标准包含和网站范围标记中分离布局,如下所示:
的Site.Master:
<%@ Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="language" content="en">
<title><asp:ContentPlaceHolder ID="Title" runat="server"><%= Model.Page.Title %></asp:ContentPlaceHolder></title>
<% Html.RenderPartial("Head"); %>
<meta name="robots" content="index, follow">
<meta name="robots" content="noodp">
<asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</head>
<body >
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</body>
</html>
然后使用Site.Master,
让另一个主人Standard.Master:
<%@ Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" MasterPageFile="Site.Master" %>
<asp:Content ContentPlaceHolderID="ExtraHead" runat="server">
<asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</asp:Content>
答案 1 :(得分:10)
是的。我刚刚在http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/
看到了一篇关于此事的博客文章很酷的东西。