Skip to content

StaticInputTagHelper

Inherits: TagHelper HTML Target: <input>

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).

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

Guid, string, int, long, short, byte, float, double, decimal, DateTime and their nullable counterparts. bool is not supported — checkbox inputs go through StaticCheckboxTagHelper.

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.

When Type is not set, the inferred value comes from:

  1. [HiddenInput] on the inner property → hidden.
  2. [DataType(DataType.Password)]password.
  3. [DataType(DataType.EmailAddress)]email.
  4. [DataType(DataType.Url)]url.
  5. [DataType(DataType.PhoneNumber)]tel.
  6. The inner property’s CLR type:
    • string / Guidtext
    • any integer / floating-point / decimal → number
    • DateTimedate
    • everything else → text

When processed, the tag helper:

  1. Validates the inner model type is supported (throws ArgumentException otherwise).
  2. Validates an explicit Type (if provided) is in the supported set.
  3. Resolves the final type and sets it on the output.
  4. Sets name, id and the full set of data-val-* attributes through StaticHeadlessUtils.
  5. Populates value from the model value when no explicit value was authored.
ConditionException
Inner property is not one of the supported model typesArgumentException
Explicit type is not in the supported set (e.g. "checkbox", "radio", "not-a-type")ArgumentException