Aspnetcore: Why do the templates not use the async method for rendering sections (RenderSectionAsync)?

Created on 13 Aug 2019  ·  5Comments  ·  Source: dotnet/aspnetcore

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:

c# 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.

Done area-mvc help wanted task

All 5 comments

Thanks @poke. We'll address that for the 5.0 release.

Cool, good to know that it wasn’t a deliberate choice then!

If you want, then I could submit a PR to update the templates later.

That would be great.

If you want, then I could submit a PR to update the templates later.

My PR was merged so this can be closed 😊

Thanks @poke!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KerolosMalak picture KerolosMalak  ·  269Comments

mkArtakMSFT picture mkArtakMSFT  ·  89Comments

radenkozec picture radenkozec  ·  114Comments

zorthgo picture zorthgo  ·  136Comments

Rast1234 picture Rast1234  ·  104Comments