StaticLabelTagHelper
Inherits: TagHelper
HTML Target: <label>
Section titled “StaticFor”
Section titled “LabelContent”
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.
Namespace
Section titled “Namespace”TechGems.StaticComponents.Headless.TagHelpersHTML Target Element
Section titled “HTML Target Element”<label static-for="@Model.InputExpression"></label><label static-for="@Model.InputExpression" class="…"></label>Public Properties
Section titled “Public Properties”StaticFor
Section titled “StaticFor”[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.
LabelContent
Section titled “LabelContent”[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.
Behavior
Section titled “Behavior”When processed, the tag helper:
- Sets the
forattribute to the inner expression’sName. - Sets the label’s text content to
LabelContent.
Related
Section titled “Related”- Headless Components — Feature guide.
- StaticLabel
- HeadlessUtils —
GetLabelContentperforms the same resolution outside the tag helper.