3
我想在MVC中創建嵌套的母版頁。在主母版頁中,我有一個使用Html.RenderPartial呈現的局部視圖。在我的視圖中直接使用主母版頁時,此工作正常。當我擁有主母版頁的子母版頁時,會出現問題。在使用子母版頁時,RenderPartial方法不起作用。代碼如下。MVC母版頁和渲染部分
這是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 15:47:33
html不能渲染。沒有任何錯誤或任何事情。使用子母版頁時,控件未創建。 – Quadwwchs 2010-10-25 16:11:34