This seems very strange to me, if I do
@RenderSection("scripts", required: false)
then it works perfectly fine, but if I do
@{
RenderSection("scripts", required: false);
}
then the scripts section will not get rendered and I would get "The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "scripts"." error
Any idea why RenderSection/Script.Render cannot be inside a code block?
Edit: I have tried to put a break point inside the code block and the break point is getting hit when the page loads, and the RenderSection method executes without any exception
RenderSection
does not write anything. Instead this methods returns an HelperResult
which implements IHtmlString
and can be render to the page by using its WriteTo
method.
@{
HelperResult renderSection = RenderSection("scripts", required: false);
renderSection.WriteTo(Output);
}
When using @RenderSection
it automatically render it to the page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With