我正在尝试在MVC中创建嵌套的母版页。在主母版页中,我有一个使用Html.RenderPartial呈现的局部视图。当直接在我的视图中使用主母版页时,这很好用。当我拥有主母版页的子母版页时,就会出现问题。使用子母版页时,RenderPartial方法不起作用。代码如下。
这是RenderPartial的限制吗?
主页-
<%@ Master Language="VB" Inherits="System.Web.Mvc.ViewMasterPage"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
html
{
background-color:gray;
}
.column
{
float:left;
width:300px;
border:solid 1px black;
margin-right:10px;
padding:5px;
background-color:white;
min-height:500px;
}
</style>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<h1>My Website</h1>
<div class="column">
<asp:ContentPlaceHolder ID="Column1Content" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="column">
<asp:ContentPlaceHolder ID="Column2Content" runat="server">
<%Html.RenderPartial("TestControl")%>
</asp:ContentPlaceHolder>
</div>
</body>
</html>子母版页-
<%@ Master Language="VB" Inherits="System.Web.Mvc.ViewMasterPage" MasterPageFile="~/Views/ViewJob/Parent.Master" %>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
<asp:ContentPlaceHolder ID="head" runat="server" >
</asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ID="ContentPlaceHolder1" ContentPlaceHolderID="Column1Content" runat="server" >
<b>This is from the child master!!!</b>
<asp:ContentPlaceHolder ID="Column1Content" runat="server" />
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" ContentPlaceHolderID="Column2Content" runat="server">
<asp:ContentPlaceHolder ID="Column2Content" runat="server" >
</asp:ContentPlaceHolder>
</asp:Content>发布于 2010-10-25 23:47:05
您的RenderPartial位于主页的ContentPlaceHolder中,而您的子母版页会覆盖该RenderPartial。
更改此设置:
<h1>My Website</h1>
<div class="column">
<asp:ContentPlaceHolder ID="Column1Content" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="column">
<asp:ContentPlaceHolder ID="Column2Content" runat="server">
<%Html.RenderPartial("TestControl")%>
</asp:ContentPlaceHolder>
</div>
要这样做:
<h1>My Website</h1>
<div class="column">
<asp:ContentPlaceHolder ID="Column1Content" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="column">
<%Html.RenderPartial("TestControl")%>
<asp:ContentPlaceHolder ID="Column2Content" runat="server">
</asp:ContentPlaceHolder>
</div>
https://stackoverflow.com/questions/4016274
复制相似问题