StaticScriptRenderer
Inherits: TagHelper
HTML Target: <render-static-scripts />
~/Pages/Shared/_Layout.cshtml
Section titled “ViewContext”
StaticScriptRenderer is a tag helper that outputs all scripts that were teleported via StaticScript components using the teleport-script attribute. It acts as the collection point where deferred scripts are rendered into the page.
Namespace
Section titled “Namespace”TechGems.StaticComponentsHTML Target Element
Section titled “HTML Target Element”<render-static-scripts />This is a self-closing tag with no end tag (void element).
Place <render-static-scripts /> in your layout, typically just before the closing </body> tag:
<html><head>...</head><body> @RenderBody()
<render-static-scripts /></body></html>Any <script static-script teleport-script> blocks in your components will be collected during rendering and output at this location.
Public Properties
Section titled “Public Properties”ViewContext
Section titled “ViewContext”[HtmlAttributeNotBound][ViewContext]public ViewContext? ViewContext { get; set; }The View Context injected by ASP.NET Core at runtime. Used to access HttpContext.Items, where teleported scripts are stored. This property should not be set manually.
Behavior
Section titled “Behavior”- Reads the list of teleported scripts from
HttpContext.Items. - If no scripts were teleported, suppresses output entirely (no HTML is rendered).
- If scripts exist, renders them wrapped in HTML comments for easy identification:
<!-- Static Scripts --><script>console.log("teleported script 1");</script><script>console.log("teleported script 2");</script><!-- Static Scripts End -->Related
Section titled “Related”- StaticScript — The tag helper that teleports scripts
- Static Scripts — Feature guide with detailed examples