Skip to content

Why do the templates not use the async method for rendering sections (RenderSectionAsync)? #13091

@poke

Description

@poke

When looking at the Razor layouts that are included in the standard templates, why do they use the synchronous method RenderSection instead of the asynchronous RenderSectionAsync?

Looking at the implementation of RenderSection, it will actually block using an awaiter:

var task = RenderSectionAsyncCore(name, required);
return task.GetAwaiter().GetResult();

That seems to be an odd preference to make in the default templates.

I understand that it may look somewhat verbose to do @await RenderSectionAsync("foo") instead of just @RenderSection("foo") but if there was no difference, then what would be the point of the async method? And while the Script sections probably won’t contain that much content, showing users how to do it “properly” would probably still be a good thing to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoneThis issue has been fixedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templateshelp wantedUp for grabs. We would accept a PR to help resolve this issuetask

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions