Skip to content

StaticRadio

Abstract Inherits: StaticInputBase

StaticRadio is the headless base class for radio <input> components. Unlike a checkbox, each radio instance represents a single option — so the Value property is required and the checked state is derived by comparing it against the bound model value.

Inside the component’s Razor template, bind the inner <input> via the static-radio-for tag helper.

TechGems.StaticComponents.Headless
using TechGems.StaticComponents.Headless;
namespace YourAssembly.Views.Components;
public class PinesRadio : StaticRadio { }
@* ~/Views/Components/PinesRadio.cshtml *@
@model PinesRadio
<label class="flex items-center gap-2">
<input static-radio-for="@Model.InputExpression"
value="@Model.Value"
disabled="@(Model.Disabled ? "disabled" : null)"
class="" />
@if (Model.ShowLabel)
{
<span>@Model.Value</span>
}
</label>
@* consumer view *@
<pines-radio asp-for="Form.Plan" value="basic"></pines-radio>
<pines-radio asp-for="Form.Plan" value="pro"></pines-radio>
<pines-radio asp-for="Form.Plan" value="enterprise"></pines-radio>
[HtmlAttributeName("value")]
public string? Value { get; set; }

The option value this radio instance represents. The static-radio-for tag helper requires this to be set — it throws ArgumentException if Value is null — and uses it both as the rendered value attribute and as the comparison key for deciding whether the radio is checked.

AttributeValue
HTML attributevalue
RequiredYes (the tag helper throws if absent)
Defaultnull
  • InputExpression (asp-for)
  • ShowLabel (show-label)
  • Disabled (disabled)

See StaticInputBase for the full descriptions.

ProcessAsync(TagHelperContext context, TagHelperOutput output)

Section titled “ProcessAsync(TagHelperContext context, TagHelperOutput output)”
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)

Delegates to StaticInputBase.ProcessAsync.