Note that there are some explanatory texts on larger screens.

plurals
  1. PORazor Sections Quirks
    text
    copied!<p>I was wondering if someone here could shed some light on some questions I was having lately about Razor.</p> <p>1) Basically, I wanted to split section definition into multiple parts? Why? Because I wanted to.</p> <p>Sadly using @section "sectionname" twice threw an exception.</p> <p>Looking deeper into the Razor source, I saw that Razor checked if a section had already been defined and threw an exception if it was already defined.</p> <p>As Razor uses delegates to render sections, I changed the code to use Delegate.Combine (if a section had been defined before), and it worked, I was now able to create a Section that was declared twice (or more). </p> <p>2) When a section is defined in a View but not rendered in the layout page an Exception is thrown. I haven't seen an elegant solution to overcome this. If I want to use a View page with multiple layout pages... This is kind of a problem.</p> <p>Looking at the source (again) there's just a foreach that checks if every section defined in the view has been rendered, and then it throws an exception if a section hasn't been rendered.</p> <p>I have thought of some solutions (especially for my second question, inheriting from the view base class and exposing the non-rendered sections to the layout page and doing some handling), but they seem... kind of like hacks. Are there any better solutions then actually changing the source? </p> <p>Not really important, but if anyone also has any insight on the design decisions that led Razor to be this way, I'd also be grateful, as this seems to be a very restrictive design.</p> <p><strong>update</strong>:</p> <p>@davidferguson and @takepara you've got it wrong. My problem isn't with defining a section in the layout, and not defining it in the view, but <em>the other way around</em>. Defining it in the View but not defining it in the layout.</p>
 

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