Skip to content

StaticNode

Abstract Inherits: TagHelper

StaticNode is a lightweight abstract base class for creating leaf-level components that do not support child content or slots. Like StaticComponent, it extends TagHelper and renders a Razor partial view with itself as the model, but omits all composition features for simplicity and clarity of intent.

Use StaticNode when your component is self-contained and does not need to wrap inner HTML or accept named slots.

TechGems.StaticComponents
using TechGems.StaticComponents;
namespace YourAssembly.Views.Components;
public class AvatarComponent : StaticNode
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}
@using YourAssembly.Views.Components;
@model AvatarComponent
<div class="avatar">
<img src="@Model.ImageUrl" alt="@Model.Name" />
<span>@Model.Name</span>
</div>
<!-- In a Razor Page -->
<avatar-component image-url="/img/photo.jpg" name="Jane" />

Creates the tag helper with a default Razor view route derived from the class’s full namespace, following the same convention as StaticComponent.

For example, YourAssembly.Views.Components.AvatarComponent resolves to ~/Views/Components/AvatarComponent.cshtml.

Creates the tag helper with a custom Razor view route, overriding the default convention.

ParameterTypeDescription
razorViewRoutestringThe explicit path to the Razor partial view.
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext? ViewContext { protected get; set; }

The View Context injected by ASP.NET Core at runtime. Provides access to the HTTP context and the HTML helper used to render partial views. This property should not be set manually.

protected IHtmlHelper GetHtmlHelper()

Retrieves the IHtmlHelper from the current ViewContext. Used internally for rendering partial views. Throws ArgumentNullException if ViewContext is null.

protected async Task RenderPartialView(TagHelperOutput output)

Renders the partial view using the default Razor view route and sends this (the component instance) as the model.

RenderPartialView(string viewRoute, TagHelperOutput output)

Section titled “RenderPartialView(string viewRoute, TagHelperOutput output)”
protected async Task RenderPartialView(string viewRoute, TagHelperOutput output)

Renders a partial view at the specified route, sending this as the model.

ParameterTypeDescription
viewRoutestringPath to the Razor partial view.
outputTagHelperOutputThe tag helper output to write into.

RenderPartialView<T>(string viewRoute, TagHelperOutput output, T model)

Section titled “RenderPartialView<T>(string viewRoute, TagHelperOutput output, T model)”
protected async Task RenderPartialView<T>(string viewRoute, TagHelperOutput output, T model)

Renders a partial view at the specified route with a custom model instead of the component itself.

ParameterTypeDescription
viewRoutestringPath to the Razor partial view.
outputTagHelperOutputThe tag helper output to write into.
modelTThe model to pass to the partial view.
FeatureStaticComponentStaticNode
Razor partial viewYesYes
Self as view modelYesYes
Child content (ChildContent)YesNo
Named slots (RenderSlot)YesNo
Component nesting stackYesNo