Search code examples
asp.net-mvcrazorengine

Why RenderBody() not working inside code


Why in a ASP.NET MVC Razor Layout Page

@if (true)
{
    <div>@RenderBody()</div>
}

works, However the code below does not?

@if (true)
{
    RenderBody();
}

If will execute the codes that RenderBody() suppose to render, but output nothing in the final result.


Solution

  • Try this.

    @if (true)
    {
      @RenderBody();
    }