Skip to content

StaticLabelTagHelper

Inherits: TagHelper HTML Target: <label>

StaticLabelTagHelper is the tag helper that powers static-for on <label> elements. It populates the for attribute and the label content using the doubly-wrapped ModelExpression produced by a headless component.

This tag helper is used declaratively — apply the static-for attribute on a <label> inside a Razor template for a headless input or label component.

TechGems.StaticComponents.Headless.TagHelpers
<label static-for="@Model.InputExpression"></label>
<label static-for="@Model.InputExpression" class=""></label>
[HtmlAttributeName("static-for")]
public ModelExpression StaticFor { get; set; }

The outer ModelExpression — its .ModelExplorer.Model is expected to be another ModelExpression bound to the consumer’s actual property.

[HtmlAttributeNotBound]
public string LabelContent { get; }

The text rendered inside the <label>. Resolves to the inner property’s [DisplayName] if present, otherwise the inner property’s name, otherwise an empty string.

When processed, the tag helper:

  1. Sets the for attribute to the inner expression’s Name.
  2. Sets the label’s text content to LabelContent.