Razor use RenderSection when you don't know the name of it

Assume the child view:

@Section Section1 {
   @:Section1 Stuff

@Section Section2 {
   @:Section2 Stuff

@Section ExtraSection {
   @:Extra Section Stuff

How can I setup the master View so that Section1 and Section2 go to their place, and all the rest get handled in a unified way? (For example like a @RenderAllOtherSections())

@RenderAllOtherSections() // ExtraSection is rendered here. How?

Update: After examining the base object of the razor view webpages, I have found that there is a dictionary with the sections that were defined in the previous(calling) view. It lies in PreviousSectionWriters parameter, but this has a private get. Also, this dictionary is actually the second item in the SectionWritersStack stack, but the stack also has a private get. The sections that were already rendered are stored as "done" in HashSet<string> _renderedSections , which is private too.

In short, the stuff I need to access from WebPageBase are:

public abstract class WebPageBase : WebPageRenderingBase
      private HashSet<string> _renderedSections

      Dictionary<string, SectionWriter> PreviousSectionWriters // private get, its the 2nd item in SectionWritersStack
     Stack<Dictionary<string, SectionWriter>> SectionWritersStack // this would do too, but private get

So the problem now is, what can I do to be able to access those properties? A helper method bool IsSectionDefined(string name) is the only public accessible thing to use but it isn't really helpful.


That is not possible. If something like this was possible how master page will understand which section will be first, second.. and so on.?

If im understanding your case you need to render sections after the @RenderBody() Alternativle you can have something like this:

Master page
@RenderSection("PostBodySection", false) // The second parameter - false means that this section is not mandatory

And in the child view you could choose whatever to have somthing in the "PostBodySection" or not.

Need Your Help

TinyMCE and pluploader not working together

javascript jquery file-upload tinymce

I want to have an instance of both TinyMCE textarea and pluplupload custom file uploader on on web page. The problem is that in my Firefox 3.6 or Google Chrome they just don't work together. I chec...

How can I identify local files that have already been uploaded to S3, and haven't changed since then?

powershell amazon-web-services amazon-s3 aws-powershell

The below script copies all files from a folder structure then pastes them to an S3 bucket. However I want it to be able to skip files that have not been changed since the last upload, to avoid