StaticCheckboxTagHelper
Inherits: TagHelper
HTML Target: <input>
Section titled “InputExpression”
StaticCheckboxTagHelper is the tag helper that powers static-checkbox-for
on <input> elements. It always emits type="checkbox", value="true", the
paired hidden value="false" (so unchecked submits a value), and checked
based on the bool model value.
This tag helper is used declaratively — apply the static-checkbox-for
attribute on an <input> inside a Razor template for a component inheriting
from StaticCheckbox.
Namespace
Section titled “Namespace”TechGems.StaticComponents.Headless.TagHelpersHTML Target Element
Section titled “HTML Target Element”<input static-checkbox-for="@Model.InputExpression" />@model PinesCheckbox
<input static-checkbox-for="@Model.InputExpression" checked="@Model.Checked" disabled="@(Model.Disabled ? "disabled" : null)" class="…" />Public Properties
Section titled “Public Properties”InputExpression
Section titled “InputExpression”[HtmlAttributeName("static-checkbox-for")]public ModelExpression InputExpression { get; set; }The outer ModelExpression — its .ModelExplorer.Model is expected to be
another ModelExpression bound to the consumer’s bool property.
Supported Model Types
Section titled “Supported Model Types”Only bool. Any other type throws ArgumentException.
Behavior
Section titled “Behavior”When processed, the tag helper:
- Validates the inner model type is
bool(throws otherwise). - Sets
name,idand the full set ofdata-val-*attributes throughStaticHeadlessUtils. - Forces
type="checkbox"andvalue="true"on the output (overwriting any author-provided values). - Adds
checked="checked"when the bool model value istrueand no explicitcheckedattribute is already set. - Appends a paired hidden
<input type="hidden" name="…" value="false" />to the output’s PostElement so the form postsfalsewhen the checkbox is unchecked.
Error Conditions
Section titled “Error Conditions”| Condition | Exception |
|---|---|
Inner property is not bool | ArgumentException |
Related
Section titled “Related”- Headless Components — Feature guide.
- StaticCheckbox