How can I know if a non-required RenderSection exi

2019-02-01 03:28发布

问题:

@* Omitted code.. *@
@RenderBody()
@RenderSection("Sidebar", required: false)

Is there any way to know in the Omitted code part if the RenderSection Sidebar exists or not?

回答1:

@if (IsSectionDefined("Sidebar"))
{
    @RenderSection("Sidebar")
}
else
{
    <div>Some default content</div>
}


回答2:

maybe:

@RenderSection("Sidebar", required: false)