StaticInputTagHelper
StaticInputTagHelper is the tag helper that powers static-for on <input>
elements inside headless component templates. It reaches through the
doubly-wrapped ModelExpression to recover the original property metadata and
emits type, name, id, value and the data-val-* validation attributes
the built-in asp-for tag helper would produce on a regular Razor view.
This tag helper is used declaratively — you do not instantiate it
manually. Apply the static-for attribute on an <input> inside a Razor
template for a component inheriting from StaticInput (or any subclass).
Namespace
Section titled “Namespace”TechGems.StaticComponents.Headless.TagHelpersHTML Target Element
Section titled “HTML Target Element”<input static-for="@Model.InputExpression" />@model PinesInput
<input static-for="@Model.InputExpression" disabled="@(Model.Disabled ? "disabled" : null)" class="…" />Public Properties
Section titled “Public Properties”InputExpression
Section titled “InputExpression”[HtmlAttributeName("static-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("type")]public string? Type { get; set; } = null;An optional override for the rendered type attribute. When set, it must be
one of the supported HTML input types (see below); otherwise the type is
inferred from the inner property’s CLR type and [DataType] attribute.
[HtmlAttributeName("value")]public string? Value { get; set; } = null;An optional explicit override for the value attribute. When unset, the
attribute is populated from the inner property’s current model value.
Supported Model Types
Section titled “Supported Model Types”Guid, string, int, long, short, byte, float, double, decimal,
DateTime and their nullable counterparts. bool is not supported —
checkbox inputs go through StaticCheckboxTagHelper.
Supported type Values
Section titled “Supported type Values”text, number, date, email, password, tel, url, search,color, datetime-local, month, time, week, hidden"checkbox" and "radio" are not accepted — those have dedicated tag
helpers.
Type Inference
Section titled “Type Inference”When Type is not set, the inferred value comes from:
[HiddenInput]on the inner property →hidden.[DataType(DataType.Password)]→password.[DataType(DataType.EmailAddress)]→email.[DataType(DataType.Url)]→url.[DataType(DataType.PhoneNumber)]→tel.- The inner property’s CLR type:
string/Guid→text- any integer / floating-point / decimal →
number DateTime→date- everything else →
text
Behavior
Section titled “Behavior”When processed, the tag helper:
- Validates the inner model type is supported (throws
ArgumentExceptionotherwise). - Validates an explicit
Type(if provided) is in the supported set. - Resolves the final
typeand sets it on the output. - Sets
name,idand the full set ofdata-val-*attributes throughStaticHeadlessUtils. - Populates
valuefrom the model value when no explicitvaluewas authored.
Error Conditions
Section titled “Error Conditions”| Condition | Exception |
|---|---|
| Inner property is not one of the supported model types | ArgumentException |
Explicit type is not in the supported set (e.g. "checkbox", "radio", "not-a-type") | ArgumentException |
Related
Section titled “Related”- Headless Components — Feature guide.
- StaticInput
- StaticTextAreaTagHelper — same idea for
<textarea>.