Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller MVC母版页和RenderPartial_Model View Controller_Nested_Master - Fatal编程技术网

Model view controller MVC母版页和RenderPartial

Model view controller MVC母版页和RenderPartial,model-view-controller,nested,master,Model View Controller,Nested,Master,我正在尝试在MVC中创建嵌套的母版页。在主母版页中,我有一个使用Html.RenderPartial呈现的局部视图。当直接在我的视图中使用主母版页时,这很好用。当我拥有主母版页的子母版页时,就会出现问题。使用子母版页时,RenderPartial方法不起作用。代码如下 这是渲染部分的限制吗 主页面- <%@ Master Language="VB" Inherits="System.Web.Mvc.ViewMasterPage"%> <!DOCTYPE html PU

我正在尝试在MVC中创建嵌套的母版页。在主母版页中,我有一个使用Html.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>

html
{
背景颜色:灰色;
}
.栏目
{
浮动:左;
宽度:300px;
边框:实心1px黑色;
右边距:10px;
填充物:5px;
背景色:白色;
最小高度:500px;
}
我的网站
子母版页-

  <%@ 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>

这是小师傅发来的!!!

您的RenderPartial位于主母版页的ContentPlaceHolder中,您的子母版页正在覆盖该RenderPartial

更改此项:

我的网站

为此:

我的网站

你说的“不工作”是什么意思?请提供更多详细信息…html未呈现。没有错误或任何东西。使用子母版页时未创建控件。
 <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>