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 6979579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:54:18+00:00 2026-05-27T17:54:18+00:00

My problem is I can’t seem to use @RenderSection from a nested template when

  • 0

My problem is I can’t seem to use @RenderSection from a nested template when @RenderSection is defined in the base template. Currently, I have a nested base template which is linked to a child template which is then used in the view pages. When I define the @RenderSection in the base template and render it in the view pages it throws an error.

Here’s the exact problem.

I want to create a RenderSection to allow me to insert custom scripts.
My base template….

<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
 @RenderSection("HeaderContent", false) // The region of the header scripts (custom css)

</head>
<body>
@RenderBody()
</body>
</html>

I then skip the child template as I do not want to put any custom head code in there and apply it to the page itself..

@section HeaderContent {
    <script>alert("hi");</script>
}

My problem is that I cant seem to add custom head code in to the base template from my normal pages.

The following sections have been defined but have not been rendered for the layout page ~/Views/Shared/OneColLayer.cshtml": "HeaderContent.

Do I need to include a pointer to the base template in the view page?

@{
    Layout = "~/Views/Shared/BaseTemplate.cshtml";
}

My new base template

<head>
  <link rel="stylesheet" type="text/css" href="@Url.Content("~/content/layout.css")" />
  <link rel="stylesheet" type="text/css" href="@Url.Content("~/content/global.css")" />
  <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"></script>
  <script type="text/javascript" src="@Url.Content("~/js/fadeInFadeOut.js")"></script>
  <title>@ViewBag.Title</title>
  @RenderSection("HeaderContent", false)
</head>
<body>
  @RenderBody()
</body>

my new child template

@{
  Layout = "~/Views/Shared/BaseTemplate.cshtml";
}
@RenderSection("HeaderContent", false)
@RenderBody()

my view

@{
  ViewBag.Title = "Home";
  Layout = "~/Views/Shared/OneColLayer.cshtml";
}
@section HeaderContent {
  <h1>Left Content</h1>
}
<div>my view content</div>

the content gets placed in the oneCol template now the base template.

results…

<div id="Content">
   <h1>Left Content</h1>
</div>
  • 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-27T17:54:19+00:00Added an answer on May 27, 2026 at 5:54 pm

    You need to specify the sections that are allowed to pass through in the middle template.

    BaseTemplate.cshtml

    <!DOCTYPE html>
    <html>
      <head>
        <title>@ViewBag.Title</title>
        @RenderSection("HeaderContent", false) @* The region of the header scripts (custom css) *@
      </head>
    <body>
      @RenderBody()
    </body>
    </html>
    

    EDIT

    your new child template

    @{
      Layout = "~/Views/Shared/BaseTemplate.cshtml";
    }
    @section HeaderContent {
      @RenderSection("HeaderContent", false)
    }
    @RenderBody()
    

    If you put the render section inside of a section from the base template, it will render that section in the correct place on the base template.


    View.cshtml -> uses MiddleLayout.cshtml as it’s layout

    @section HeaderContent
    {
        <!-- header content that will now render -->
    }
    
    <!-- page content -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! My problem can be described the following way: I have some data which
I have tried to understand and use urlencode, but the problem can't be solved.
I'm building a database and have run into a problem that I can't seem
I think that this problem can be sorted using reflection (a technology which I'm
I have a problem and can't solve it alone. My teacher gives me one
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
I've got a problem I can't find any solution for. I have a textfile
Hey everyone I got a javascript problem I can't seem to find a specific
This is a strange LINQ-to-SQL problem which can't evaluate as an Enumerable (in SQL)
Which problem can cause kill -9 in production application (in linux to be exact)?

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.