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

  • Home
  • SEARCH
  • 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 7677527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:26:32+00:00 2026-05-31T17:26:32+00:00

I have created VIEWS and PartialVIEWS, but so far, i have seen that VIEWS,

  • 0

I have created VIEWS and PartialVIEWS, but so far, i have seen that VIEWS, get rendered/outputted into the RenderBody() section, which is set in the _Layout.cshtml

Hence, if i have in my _Layout.cshtml …

<div id="container">
    <div id="col1"> 
        <p>Advert1 aliquip</p> 
         </div> 
         <div id="col2outer1"> 
            <div id="col2mid1">                    
                 @RenderBody()
                 <br /><b /> <br />
        </div>
       <div id="col2side1"> 
           <p>Advert2 </p> 
       </div> 
</div>

ALL VIEWS will be called within the @RenderBody() section. This will mean that Advert1 and Advert2 will always be shown on every VIEW called. However when i call a PartialView, this does not happen. The Advert1 and Advert2 does not appear. How can i get around this without manually creating the above in every PartialView.

Thanks Kindly
Naren

  • 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-31T17:26:33+00:00Added an answer on May 31, 2026 at 5:26 pm

    If you’re relying on a _ViewStart.cshtml to apply your _Layout.cshtml to your partial, don’t. Try explicitly setting the Layout in the initial code block.

    I use nested layouts for a bunch of custom editor templates in my last project, trying to get a _ViewStart.cshtml to kick in for that folder just wouldn’t work because _ViewStart is not executed for Partials. As soon as I manually specified Layout directly in the partial it was fine.

    Personally, I was happy with that – it was only a minor annoyance.

    So, as an example:

    (In ~/Views/Shared/_PartialLayout.cshtml)

    <div class="partialContainer">
    @RenderBody()
    </div>
    

    And then an example partial is as follows:

    {
      Layout = "~/Views/Shared/_PartialLayout.cshtml";
    }
    <p>Hello World!</p>
    

    (Note you have to explicitly set the layout, because _ViewStart is not processed for partials)

    At runtime – this partial will actually render:

    <div class="partialContainer">
    <p>Hello World!</p>
    </div>
    

    Which I believe is what you want to achieve.

    Note that the actual location of the partial views’ layout is not important, you can put it in a shared folder if you want, or you can put it in a particular controller’s views folder – so long as you then address it correctly in the partial view’s assignment of the Layout member, it’ll be fine.

    The answer on this other SO: Correct way to use _viewstart.cshtml and partial Razor views?, which actually makes reference to an earlier bug in Razor, too, exploits the fact that PartialViewResults don’t execute ViewStart.

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

Sidebar

Related Questions

I have a contoller that renders 3 different views. But I also have a
if i have created a view model and have a partial form that is
I have created a list view that displays the names and dates of items
We have created a new List View Style that shows thumbnails from a picture
I have created XML file,but I can't view it/output it.I know there is no
I have created an Eclipse plugin which creates a view in Eclipse. Currently it
I have a main page which uses a ViewModel I have created: public class
Using information from some of the questions here on generic views, I have created
I have a simple Widget that I've created using a ContentPart. The ContentPart has
I have a controller which renders a view (~/Views/Component/Create.aspx) no problem. When this view

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.