Forms

FormControl

Generate a validated form from your model, or lay one out by hand.

Overview

FormControl is a Blazor form that builds an editor for each property of your model, validates it with data annotations and reports every accepted value. Use it for settings, sign-up or leave-request forms without writing a field per property; when the layout matters, place the items yourself with groups, templates and tooltips. PropertyGridControl edits an object row by row, writing each change as it is made.

Examples

#Generated form

One line of markup, an editor for each of nine leave-request properties (the tenth, Id, is hidden with AutoGenerateField = false): clear Employee or enter 25 in Days to see the validation messages, then press Save.

Not saved yet.

#Hand-built form: group, template, tooltip, buttons

Lay out a hiring manager's request for Reservations agents yourself: a grouped fieldset, a templated openings stepper, a validation tooltip on "Name rules" and your own buttons.

Contact
Name rules
1
A template replaces the editor; the field context sets the value.

Not sent. Last change: none.

#Property grid: edit an object

Edit an employee record directly; each change is written as it is made. Press Level as buttons to draw Level with your own editor through CustomEditor.

Employee Id
Name
Office
Vacation Days
Training Budget
Level
Full Time
Start Date

EMP-0042: Luna Goodlove, Kyoto, Senior, 20 vacation days, started Mar 4, 2024, training budget 1200.00, full time. Changes reported: 0.

Documentation

ParameterTypeDefaultDescription
Modelobject?nullThe object to edit. A different instance creates a new EditContext; the form throws when both Model and EditContext are set, or neither.
EditContextEditContext?nullA context you own, for sharing validation state with code outside the form.
EnableDataAnnotationsbooltrueAdds the DataAnnotationsValidator, so Required, Range, MinLength, EmailAddress and the rest run for a field as its value is accepted, and for the whole model on submit.
ShowValidationSummarybooltrueShows the list of all messages above the items.
ShowSubmitButtonbooltrueShows the default submit button under the items; ignored when ButtonsTemplate is set.
SubmitTextstring"Save"Caption of the default submit button.
Columnsint1Number of columns the items flow into; one column under 600 px wide.
ColumnSpacingstring"12px"Gap between the items.
ChildContentRenderFragment?nullYour own items, groups and templates. When null, the items are generated from the model.
ButtonsTemplateRenderFragment?nullReplaces the default submit button; a ButtonControl with ButtonType="submit" still submits.
ValidatorTemplateRenderFragment?nullExtra validator components rendered inside the form, for example a custom validator alongside or instead of data annotations.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.