GenericFormField<TModel> Class
Represents a field in a generic form, providing metadata and rendering capabilities for a model property.
public sealed class GenericFormField<TModel>Type parameters
TModel- The type of the model containing the field.
Remarks
This class is used by the GenericForm component to automatically generate form fields based on model properties. It reads metadata from attributes such as DisplayAttribute, DisplayNameAttribute, DescriptionAttribute, and EditorAttribute to customize the field's appearance and behavior.
Properties
| Name | Description |
|---|---|
| Description | Gets the description for the field from DisplayAttribute or DescriptionAttribute. |
| DisplayName | Gets the display name for the field, determined from DisplayAttribute or DisplayNameAttribute, or the property name if no attribute is present. |
| DisplayOrder | Gets the display order for the field from the DisplayAttribute. Returns 10000 if not specified, as recommended by Microsoft. |
| EditorId | Gets the HTML id attribute value for the editor element. |
| EditorTemplate | Gets a render fragment that renders the appropriate input editor for this field. |
| FieldValidationTemplate | Gets a render fragment that renders the validation message for this field, or null if field validation is disabled. |
| Owner | Gets the model instance that owns this field. |
| Prompt | Gets the prompt text for the field from DisplayAttribute. |
| Property | Gets the PropertyInfo representing the model property for this field. |
| PropertyType | Gets the property type. |
| Value | Gets or sets the current value of the field. |
Description
GenericFormField.csGets the description for the field from DisplayAttribute or DescriptionAttribute.
public string? Description { get; }Property value
DisplayName
GenericFormField.csGets the display name for the field, determined from DisplayAttribute or DisplayNameAttribute, or the property name if no attribute is present.
public string DisplayName { get; }Property value
DisplayOrder
GenericFormField.csGets the display order for the field from the DisplayAttribute. Returns 10000 if not specified, as recommended by Microsoft.
public int DisplayOrder { get; }Property value
EditorId
GenericFormField.csEditorTemplate
GenericFormField.csGets a render fragment that renders the appropriate input editor for this field.
public RenderFragment EditorTemplate { get; }Property value
FieldValidationTemplate
GenericFormField.csGets a render fragment that renders the validation message for this field, or null if field validation is disabled.
public RenderFragment? FieldValidationTemplate { get; }Property value
Owner
GenericFormField.csGets the model instance that owns this field.
public TModel Owner { get; }Property value
TModel
Prompt
GenericFormField.csGets the prompt text for the field from DisplayAttribute.
public string? Prompt { get; }Property value
Property
GenericFormField.csGets the PropertyInfo representing the model property for this field.
public PropertyInfo Property { get; }Property value
PropertyType
GenericFormField.csValue
GenericFormField.csEvents
| Name | Description |
|---|---|
| ValueChanged | Occurs when the field value changes. |
ValueChanged
Occurs when the field value changes.
public event EventHandler? ValueChanged