MVC and RenderPartial Home

I am trying to create nested master pages in MVC. On the main main page, I have a partial view that is displayed using Html.RenderPartial. This works great when using the main homepage right on my screen. The problem arises when I have a home page for children of the main home page. When using the child’s main page, the RenderPartial method does not work. The code is below.

Is this a RenderPartial limitation?

The main main page is

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

Child Wizard Page -

  <%@ 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>
+3
source share
1 answer

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>

+3

Source: https://habr.com/ru/post/1771333/


All Articles