Demos About Radzen
Search Results for

    Show / Hide Table of Contents

    Class RadzenDataAnnotationValidator

    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<TItem>. 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.

    Inheritance
    object
    ComponentBase
    RadzenComponent
    ValidatorBase
    RadzenDataAnnotationValidator
    Implements
    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormValidator
    Inherited Members
    ValidatorBase.messages
    ValidatorBase.SetParametersAsync(ParameterView)
    ValidatorBase.GetComponentCssClass()
    ValidatorBase.Dispose()
    ValidatorBase.BuildRenderTree(RenderTreeBuilder)
    ValidatorBase.Form
    ValidatorBase.Component
    ValidatorBase.Popup
    ValidatorBase.IsValid
    ValidatorBase.EditContext
    RadzenComponent.OnMouseEnter()
    RadzenComponent.OnMouseLeave()
    RadzenComponent.OnContextMenu(MouseEventArgs)
    RadzenComponent.GetCssClass()
    RadzenComponent.GetId()
    RadzenComponent.Debounce(Func<Task>, int)
    RadzenComponent.OnInitialized()
    RadzenComponent.OnAfterRenderAsync(bool)
    RadzenComponent.RaiseContextMenu(MouseEventArgs)
    RadzenComponent.RaiseMouseEnter()
    RadzenComponent.AddContextMenu()
    RadzenComponent.RaiseMouseLeave()
    RadzenComponent.Attributes
    RadzenComponent.Element
    RadzenComponent.MouseEnter
    RadzenComponent.MouseLeave
    RadzenComponent.ContextMenu
    RadzenComponent.Culture
    RadzenComponent.DefaultCulture
    RadzenComponent.Style
    RadzenComponent.Visible
    RadzenComponent.UniqueID
    RadzenComponent.JSRuntime
    RadzenComponent.IsJSRuntimeAvailable
    RadzenComponent.Reference
    RadzenComponent.CurrentStyle
    ComponentBase.OnInitializedAsync()
    ComponentBase.OnParametersSet()
    ComponentBase.OnParametersSetAsync()
    ComponentBase.StateHasChanged()
    ComponentBase.ShouldRender()
    ComponentBase.OnAfterRender(bool)
    ComponentBase.InvokeAsync(Action)
    ComponentBase.InvokeAsync(Func<Task>)
    ComponentBase.DispatchExceptionAsync(Exception)
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Radzen.Blazor
    Assembly: Radzen.Blazor.dll
    Syntax
    public class RadzenDataAnnotationValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, IRadzenFormValidator
    Examples

    Model-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=" | " />

    Constructors

    RadzenDataAnnotationValidator()

    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<TItem>. 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.

    Declaration
    public RadzenDataAnnotationValidator()
    Examples

    Model-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=" | " />

    Properties

    MessageSeparator

    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.

    Declaration
    [Parameter]
    public string MessageSeparator { get; set; }
    Property Value
    Type Description
    string

    The message separator text. Default is " and ".

    ServiceProvider

    Service provider injected from the Dependency Injection (DI) container.

    Declaration
    [Inject]
    public IServiceProvider ServiceProvider { get; set; }
    Property Value
    Type Description
    IServiceProvider

    Text

    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.

    Declaration
    [Parameter]
    public override string Text { get; set; }
    Property Value
    Type Description
    string

    The validation error message(s).

    Overrides
    ValidatorBase.Text

    Methods

    Validate(IRadzenFormComponent)

    Runs validation against the specified component.

    Declaration
    protected override bool Validate(IRadzenFormComponent component)
    Parameters
    Type Name Description
    IRadzenFormComponent component

    The component to validate.

    Returns
    Type Description
    bool

    true if validation is successful, false otherwise.

    Overrides
    ValidatorBase.Validate(IRadzenFormComponent)

    Implements

    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormValidator

    Introducing Radzen Blazor Studio

    Radzen Blazor Studio is a software development environment that empowers developers to design, build and deploy Blazor applications without the traditional hurdles. Write less code and get more done.

    Learn More

    Download Now
    Download Now
    In This Article
    Back to top Radzen Blazor Components, © 2018-2025 Radzen. Source Code licensed under MIT