A validator component that validates form inputs using Data Annotations attributes defined on model properties. RadzenDataAnnotationValidator enables automatic validation based on attributes like [Required], [StringLength], [Range], [EmailAddress], etc. Must be placed inside a RadzenTemplateForm<T>. Uses the standard .NET validation attributes from System.ComponentModel.DataAnnotations. Reads all validation attributes on a model property and validates the input accordingly. Benefits include centralized validation (define rules once on the model, use everywhere), support for multiple validation attributes per property, built-in attributes (Required, StringLength, Range, EmailAddress, Phone, Url, RegularExpression, etc.), works with custom ValidationAttribute implementations, and multiple errors joined with MessageSeparator. Ideal when your validation rules are already defined on your data models using data annotations. Automatically extracts error messages from the attributes' ErrorMessage properties.
ValidatorBase.SetParametersAsync
ValidatorBase.GetComponentCssClass
RadzenComponent.OnAfterRenderAsync
RadzenComponent.RaiseContextMenu
RadzenComponent.RaiseMouseEnter
RadzenComponent.AddContextMenu
RadzenComponent.RaiseMouseLeave
RadzenComponent.OnBecameInvisible
RadzenComponent.DefaultCulture
RadzenComponent.IsJSRuntimeAvailable
ComponentBase.OnInitializedAsync
ComponentBase.OnParametersSet
ComponentBase.OnParametersSetAsync
ComponentBase.StateHasChanged
ComponentBase.ShouldRender
ComponentBase.OnAfterRender
ComponentBase.InvokeAsync
ComponentBase.DispatchExceptionAsync
ComponentBase.RendererInfo
ComponentBase.Assets
ComponentBase.AssignedRenderMode
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
public class RadzenDataAnnotationValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormValidatorModel-based validation with data annotations:
<RadzenTemplateForm TItem="UserModel" Data=@user>
<RadzenTextBox Name="Email" @bind-Value=@user.Email />
<RadzenDataAnnotationValidator Component="Email" />
</RadzenTemplateForm>
@code {
class UserModel
{
[Required(ErrorMessage = "Email is required")]
[EmailAddress(ErrorMessage = "Invalid email format")]
[StringLength(100, ErrorMessage = "Email too long")]
public string Email { get; set; }
}
UserModel user = new UserModel();
}
Custom error separator:
<RadzenDataAnnotationValidator Component="Name" MessageSeparator=" | " />A validator component that validates form inputs using Data Annotations attributes defined on model properties. RadzenDataAnnotationValidator enables automatic validation based on attributes like [Required], [StringLength], [Range], [EmailAddress], etc. Must be placed inside a RadzenTemplateForm<T>. Uses the standard .NET validation attributes from System.ComponentModel.DataAnnotations. Reads all validation attributes on a model property and validates the input accordingly. Benefits include centralized validation (define rules once on the model, use everywhere), support for multiple validation attributes per property, built-in attributes (Required, StringLength, Range, EmailAddress, Phone, Url, RegularExpression, etc.), works with custom ValidationAttribute implementations, and multiple errors joined with MessageSeparator. Ideal when your validation rules are already defined on your data models using data annotations. Automatically extracts error messages from the attributes' ErrorMessage properties.
public RadzenDataAnnotationValidator()Gets or sets the text used to join multiple validation error messages. When multiple data annotation attributes fail (e.g., both Required and StringLength), their messages are combined with this separator.
public string MessageSeparator { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the text used to join multiple validation error messages. When multiple data annotation attributes fail (e.g., both Required and StringLength), their messages are combined with this separator. |
Service provider injected from the Dependency Injection (DI) container.
public IServiceProvider ServiceProvider { get; set; }
| Type | Description |
|---|---|
| IServiceProvider | Service provider injected from the Dependency Injection (DI) container. |
Gets or sets the validation error message. This property is automatically populated with error messages from data annotation attributes when validation fails. If multiple attributes fail, messages are joined using MessageSeparator.
public string Text { get; set; }
| Type | Description |
|---|---|
| string | Gets or sets the validation error message. This property is automatically populated with error messages from data annotation attributes when validation fails. If multiple attributes fail, messages are joined using MessageSeparator. |
protected override bool Validate(IRadzenFormComponent component)
| Type | Name | Description |
|---|---|---|
| IRadzenFormComponent | component |
| Type | Description |
|---|---|
| bool |