Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Allow to define section or/and body without the need to render it #3293

@dan2dev

Description

@dan2dev

It would be nice if we could just prevent the render of the body or/and the section like this without get the exception:

@if (someLogicIsFalseHere) {
    RenderSection("adminMenu");
}

An unhandled exception occurred while processing the request.

InvalidOperationException: The following sections have been defined but have not been rendered by the page at '/Views/Shared/_Layout.cshtml': 'adminMenu'.

I use the "section" to make various versions of the views using the same "layout.cshtml" for different browsers, users, permissions and requests types with the same controller and model.

The way I current make this in asp.net 4.5 is like the code bellow, but this workaround doesn't work properly in asp.net 5 beta 7. This was discussed in the issue #3283

@if (someLogicIsFalseHere) {
    WriteTo(TextWriter.Null, RenderBody());
    WriteTo(TextWriter.Null, RenderSection("adminMenu"));
    RenderSection("alternativeMenu");
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions