Skip to content

FormFieldTagHelper

StrutTower edited this page Feb 23, 2024 · 3 revisions

Tag helper that generates all of the standard elements used in a form for a field

Usage

<formField asp-for="StringProperty"></formField>
<formField asp-for="IntProperty"></formField>
<formField asp-for="DateOnlyProperty" renderer="Date"></formField>

Output

<div class="mb-3">
    <label for="StringProperty">StringProperty</label>
    <input type="text" id="StringProperty" name="StringProperty" class="form-control" />
    <span>[Default validate span]</span>
    <div class="ps-2 text-muted small">Description of property</div>
</div>
<div class="mb-3">
    <label for="IntProperty">IntProperty</label>
    <input type="number" id="IntProperty" name="IntProperty" class="form-control" />
    <span>[Default validate span]</span>
    <div class="ps-2 text-muted small">Description of property</div>
</div>
<div class="mb-3">
    <label for="DateOnlyProperty">DateOnlyProperty</label>
    <input type="date" id="DateOnlyProperty" name="DateOnlyProperty" class="form-control" />
    <span>[Default validate span]</span>
    <div class="ps-2 text-muted small">Description of property</div>
</div>

Attributes

Name Required Data Type Description
asp-for Required ModelExpression The property for this field
template Optional String Key name the HtmlRender that will be used for rendering the input
label Optional String Overrides the default label string used for this field
input-css Optional String Add the supplied class values to the input element

HtmlRenders

More info on HtmlRenderers.

Clone this wiki locally