Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:21:40+00:00 2026-05-27T12:21:40+00:00

I have a shared view located in Shared/Header.aspx and I want to render this

  • 0

I have a shared view located in Shared/Header.aspx and I want to render this as part of the HeaderContent ContentPlaceHolder. My master page contains:

<asp:ContentPlaceHolder ID="HeaderContent" runat="server" />

and I want to be able to tell MVC to populate that content place holder with the Shared/Header view, which contains:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
    ....
</asp:Content>

At the moment in each of the pages where I want the HeaderContent to be populated (and on some pages I don’t want it to be) I do this:

<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" runat="server">
    <% Html.RenderPartial("Header"); %>
</asp:Content>

Is there any way I can effectively do the above but from the Controller handling the request (or a child class of ViewPage)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:21:40+00:00Added an answer on May 27, 2026 at 12:21 pm

    If you want to do this from the controller, then you could pass a property in the ViewData, which could be picked up from the layout page. E.g. in a controller action:

    ViewData["ShowHeader"] = true;
    

    Then in the layout page you could say

    <% if(ViewData["ShowHeader"] != null && ((bool)ViewData["ShowHeader"]))
    {
        Html.RenderPartial("Header");
    } %>
    

    That way you don’t need the extra content placeholder too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that is strongly typed: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage<MPKwithMVC.Models.SmartFormViewModel>
I have a shared master view for all my other views. It's in this
I have a simple view: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %> <asp:Content ID=Content1
If i have the following strongly-typed view: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage<XXX.DomainModel.Core.Locations.Location> %>
I have this class: class View(object): def main_page(self, extra_placeholders = None): file = '/media/Shared/sites/www/subdomains/pypular/static/layout.tmpl'
I have a shared view called NotAuthorised in the folder 'Views/Shared'. I want to
I have a shared view in my _Layout.cshtml for my header named _Header.cshtml. I
I have one asp.net page. I want to add this page to asp.net mvc
I have a partial view that is shared between two controllers and I'm trying
I have a partial view (user control) that is shared by my Create and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.