Is it possible to prgrammatically get the section names from a C# Razor view layout file? Without parsing the page manually.
Say for example you have a layout file named _Layout.cshtml with @RenderSection(“scripts”) at the bottom of it and I want to retrieve the name “scripts”.
Other than parsing the Razor file there is no way of obtaining this information programatically. Even inside the web application and the view itself it could be challenging. Sections in Razor are internally implemented as a private
Stack<T>on the WebPageBase class and depending in which moment of the template execution you query this private field (using reflection) it might or might not contain the information.