How can I know if a non-required RenderSection exi

2019-02-01 03:23发布

@* 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?

2条回答
Emotional °昔
2楼-- · 2019-02-01 03:42

maybe:

@RenderSection("Sidebar", required: false)
查看更多
贪生不怕死
3楼-- · 2019-02-01 03:50
@if (IsSectionDefined("Sidebar"))
{
    @RenderSection("Sidebar")
}
else
{
    <div>Some default content</div>
}
查看更多
登录 后发表回答