As noted in the issue #11860, the RenderSection example is confusing and may create a fallacious impression that RenderSection can be used only inside other section definition. It's overloaded with information that is unnecessary for RenderSection understanding.pull/15805/head
parent
c093a361f4
commit
23a6f09e2e
|
@ -62,9 +62,9 @@ By default, every layout must call `RenderBody`. Wherever the call to `RenderBod
|
||||||
A layout can optionally reference one or more *sections*, by calling `RenderSection`. Sections provide a way to organize where certain page elements should be placed. Each call to `RenderSection` can specify whether that section is required or optional:
|
A layout can optionally reference one or more *sections*, by calling `RenderSection`. Sections provide a way to organize where certain page elements should be placed. Each call to `RenderSection` can specify whether that section is required or optional:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
@section Scripts {
|
<script type="text/javascript" src="~/scripts/global.js"></script>
|
||||||
@RenderSection("Scripts", required: false)
|
|
||||||
}
|
@RenderSection("Scripts", required: false)
|
||||||
```
|
```
|
||||||
|
|
||||||
If a required section isn't found, an exception is thrown. Individual views specify the content to be rendered within a section using the `@section` Razor syntax. If a page or view defines a section, it must be rendered (or an error will occur).
|
If a required section isn't found, an exception is thrown. Individual views specify the content to be rendered within a section using the `@section` Razor syntax. If a page or view defines a section, it must be rendered (or an error will occur).
|
||||||
|
@ -73,7 +73,7 @@ An example `@section` definition in Razor Pages view:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script type="text/javascript" src="/scripts/main.js"></script>
|
<script type="text/javascript" src="~/scripts/main.js"></script>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue