Skip to content

StaticCheckboxTagHelper

Inherits: TagHelper HTML Target: <input>

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.

TechGems.StaticComponents.Headless.TagHelpers
<input static-checkbox-for="@Model.InputExpression" />
@model PinesCheckbox
<input static-checkbox-for="@Model.InputExpression"
checked="@Model.Checked"
disabled="@(Model.Disabled ? "disabled" : null)"
class="" />
[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.

Only bool. Any other type throws ArgumentException.

When processed, the tag helper:

  1. Validates the inner model type is bool (throws otherwise).
  2. Sets name, id and the full set of data-val-* attributes through StaticHeadlessUtils.
  3. Forces type="checkbox" and value="true" on the output (overwriting any author-provided values).
  4. Adds checked="checked" when the bool model value is true and no explicit checked attribute is already set.
  5. Appends a paired hidden <input type="hidden" name="…" value="false" /> to the output’s PostElement so the form posts false when the checkbox is unchecked.
ConditionException
Inner property is not boolArgumentException