Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use <a href="http://www.asp.net/learn/mvc/tutorial-12-cs.aspx" rel="nofollow noreferrer">the master page and use content placeholders</a> for view content pages and view user controls. </p> <p>The default project template in ASP.NET MVC Framework Beta has a content placeholder for the View Content Page. There is also a View User Control for the login/logout link at the top right corner of the pages.</p> <h2>View Content Page</h2> <p>The view content pages are supposed to be used with the data that comes from the View that you are looking at. I.e. if you're browsing to the <code>Index</code> action in <code>HomeController</code>, the server will render the <code>Home/Index.aspx</code> view content page.</p> <p>In the master page you need the following line:</p> <pre><code>&lt;asp:ContentPlaceHolder ID="Holder1" runat="server" /&gt; </code></pre> <p>And in the view content page itself you compose for that place holder with the following:</p> <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="Holder1" runat="server"&gt; &lt;p&gt;This text goes to "Holder1" content place holder and I can access the ViewData.&lt;/p&gt; &lt;p&gt;&lt;%= ViewData["Message"] %&gt; &lt;/asp:Content&gt; </code></pre> <p>Each <code>asp:ContentPlaceHolder</code> corresponds to the view's <code>asp:Content</code> through the id. So if you want <strong>several</strong> placeholders like this:</p> <pre><code>&lt;asp:ContentPlaceHolder ID="Holder1" runat="server" /&gt; &lt;asp:ContentPlaceHolder ID="Holder2" runat="server" /&gt; </code></pre> <p>…you can handle them in the view content page like this:</p> <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="Holder1" runat="server"&gt; &lt;p&gt;This text goes to "Holder1" content place holder&lt;/p&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="Holder2" runat="server"&gt; &lt;p&gt;This text goes to "Holder2" content place holder&lt;/p&gt; &lt;/asp:Content&gt; </code></pre> <h2>View User Controls</h2> <p>View user controls can be used regardless of what view you are looking at. Here are some examples of viewing user controls, are taken from <a href="http://blog.wekeroad.com/2008/01/07/aspnet-mvc-using-usercontrols-usefully/" rel="nofollow noreferrer">Wekeroad's blog post about View User Controls</a>. To use a view user control:</p> <pre><code>&lt;%=Html.RenderUserControl(“~/UserControls/UserList.ascx”)%&gt; </code></pre> <p>If you have the need you can also pass data and anonymous types to it.</p> <pre><code>&lt;%=Html.RenderUserControl(“~/UserControls/UserList.ascx”,ViewData.Users, new {GroupID=2})%&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload