Skip to content

StaticCheckbox

Abstract Inherits: StaticInputBase

StaticCheckbox is the headless base class for checkbox <input> components. It adds the two attributes specific to checkboxes — Value (the value posted when the box is checked) and Checked (an explicit override of the bool model’s checked state).

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

TechGems.StaticComponents.Headless
using TechGems.StaticComponents.Headless;
namespace YourAssembly.Views.Components;
public class PinesCheckbox : StaticCheckbox { }
@* ~/Views/Components/PinesCheckbox.cshtml *@
@model PinesCheckbox
<input static-checkbox-for="@Model.InputExpression"
checked="@Model.Checked"
disabled="@(Model.Disabled ? "disabled" : null)"
class="" />
@if (Model.ShowLabel)
{
<label static-for="@Model.InputExpression" class=""></label>
}
@* consumer view *@
<pines-checkbox asp-for="Form.AcceptsTerms"></pines-checkbox>
[HtmlAttributeName("value")]
public string? Value { get; set; }

The value posted when the checkbox is checked. Optional — the static-checkbox-for tag helper unconditionally emits value="true" on the inner <input> regardless of this property, but consumers can still author it explicitly for clarity.

AttributeValue
HTML attributevalue
RequiredNo
Defaultnull
[HtmlAttributeName("checked")]
public bool Checked { get; set; } = false;

Lets a consumer mark the checkbox as checked regardless of the bound model value. Useful for visually-checked states driven by something other than the bound property.

AttributeValue
HTML attributechecked
RequiredNo
Defaultfalse
  • 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.