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.
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!