How can I know if a non-required RenderSection exists?

Thomas Bonini picture Thomas Bonini · Jul 21, 2011 · Viewed 11.7k times · Source
@* 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?

Answer

Darin Dimitrov picture Darin Dimitrov · Jul 21, 2011
@if (IsSectionDefined("Sidebar"))
{
    @RenderSection("Sidebar")
}
else
{
    <div>Some default content</div>
}