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

NameDescription
DescriptionGets the description for the field from DisplayAttribute or DescriptionAttribute.
DisplayNameGets the display name for the field, determined from DisplayAttribute or DisplayNameAttribute, or the property name if no attribute is present.
DisplayOrderGets the display order for the field from the DisplayAttribute. Returns 10000 if not specified, as recommended by Microsoft.
EditorIdGets the HTML id attribute value for the editor element.
EditorTemplateGets a render fragment that renders the appropriate input editor for this field.
FieldValidationTemplateGets a render fragment that renders the validation message for this field, or null if field validation is disabled.
OwnerGets the model instance that owns this field.
PromptGets the prompt text for the field from DisplayAttribute.
PropertyGets the PropertyInfo representing the model property for this field.
PropertyTypeGets the property type.
ValueGets or sets the current value of the field.

Gets the description for the field from DisplayAttribute or DescriptionAttribute.

public string? Description { get; }

Property value

string?

Gets 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

string

Gets the display order for the field from the DisplayAttribute. Returns 10000 if not specified, as recommended by Microsoft.

public int DisplayOrder { get; }

Property value

int

Gets the HTML id attribute value for the editor element.

public string EditorId { get; }

Property value

string

EditorTemplate

GenericFormField.cs

Gets a render fragment that renders the appropriate input editor for this field.

public RenderFragment EditorTemplate { get; }

Property value

RenderFragment

FieldValidationTemplate

GenericFormField.cs

Gets a render fragment that renders the validation message for this field, or null if field validation is disabled.

public RenderFragment? FieldValidationTemplate { get; }

Property value

RenderFragment?

Gets the model instance that owns this field.

public TModel Owner { get; }

Property value

TModel

Gets the prompt text for the field from DisplayAttribute.

public string? Prompt { get; }

Property value

string?

Gets the PropertyInfo representing the model property for this field.

public PropertyInfo Property { get; }

Property value

PropertyInfo

Gets the property type.

public Type PropertyType { get; }

Property value

Type

Gets or sets the current value of the field.

public object? Value { get; set; }

Property value

object?

Events

NameDescription
ValueChangedOccurs when the field value changes.

ValueChanged

Occurs when the field value changes.

public event EventHandler? ValueChanged