StaticRadioTagHelper
Inherits: TagHelper
HTML Target: <input>
Section titled “InputExpression”
StaticRadioTagHelper is the tag helper that powers static-radio-for on
<input> elements. It always emits type="radio", uses an explicit value
attribute as the option key, and adds checked when the bound model value
matches that key.
This tag helper is used declaratively — apply the static-radio-for
attribute on an <input> inside a Razor template for a component inheriting
from StaticRadio.
Namespace
Section titled “Namespace”TechGems.StaticComponents.Headless.TagHelpersHTML Target Element
Section titled “HTML Target Element”<input static-radio-for="@Model.InputExpression" value="…" />@model PinesRadio
<input static-radio-for="@Model.InputExpression" value="@Model.Value" disabled="@(Model.Disabled ? "disabled" : null)" class="…" />Public Properties
Section titled “Public Properties”InputExpression
Section titled “InputExpression”[HtmlAttributeName("static-radio-for")]public ModelExpression InputExpression { get; set; }The outer ModelExpression — its .ModelExplorer.Model is expected to be
another ModelExpression bound to the consumer’s actual property.
[HtmlAttributeName("value")]public string? Value { get; set; }The option value this radio instance represents. Required — the tag helper
throws ArgumentException if Value is null.
Supported Model Types
Section titled “Supported Model Types”string, int, short, long, byte, bool, Enum and their nullable
counterparts.
Behavior
Section titled “Behavior”When processed, the tag helper:
- Validates the inner model type is supported (throws otherwise).
- Validates
Valueis notnull(throws otherwise). - Forces
type="radio"on the output. - Sets
name,idand thedata-val-*attributes throughStaticHeadlessUtils. - Emits the rendered
valueattribute by formattingValuethroughFormatModelValue(invariant-culture formatting). - Adds
checked="checked"when no explicitcheckedis already on the output andValueequals the model value’s string representation.
Error Conditions
Section titled “Error Conditions”| Condition | Exception |
|---|---|
| Inner property is not one of the supported model types | ArgumentException |
Value is null | ArgumentException |
Related
Section titled “Related”- Headless Components — Feature guide.
- StaticRadio