0

I am using a @section { ... } expression inside a shared template. As I don't see the shared code rendered in the section, and since I don't find hints in the internet, I am not sure if this should work at all.

Here is how I examine:

_Shared.cshtml:
...
<div class="not-in-section">
    Not in section
</div>

@section Templates {

<div class="in-section">
    in section
</div> 
...

I see the not-in-section rendered, but not the in-section code.

In index.cshtml, I invoke like this:

...
@Html.Partial("~/Views/Shared/_Shared.cshtml")
...
@section Templates {

    <script type="x-template" id="book-template">
...

So I invoke _Shared.cshtml and also refer to @section, which works fine.

Can somebody confirm this should work, or this will never work? If it should work, what should be changed?

peter_the_oak
  • 3,353
  • 2
  • 20
  • 35
  • 1
    Sections are not supported in partials - refer [here](http://stackoverflow.com/questions/7556400/injecting-content-into-specific-sections-from-a-partial-view-asp-net-mvc-3-with) and [here](http://stackoverflow.com/questions/17876538/asp-mvc-define-section-in-partial-view) –  Mar 29 '17 at 07:09
  • @StephenMuecke, thanks a lot. That's what I needed. – peter_the_oak Mar 29 '17 at 07:53

0 Answers0