Check RenderSectionAsync in _Layout is empty or not (ASP.NET Core MVC)

40 Views Asked by At

This is my _Layout.cshtml:

@await RenderSectionAsync("SpecialHeader", required: false)

Some views have this and some don't:

@section SpecialHeader
{
    // something
}

So far so good.

Now how can I check whether RenderSectionAsync (in _Layout.cshtml) is null (empty) or not?

I want something like this:

if (RenderSectionAsync == null)   // this is in my mind
{
    // Public Header
}
else
{
    @await RenderSectionAsync("SpecialHeader", required: false)
}
0

There are 0 best solutions below