Get only the string of the error from ValidationMessage in blazor?

745 Views Asked by At

While using blazor's ValidationMessage I realized that this component wraps the error around a div and add the class validation-message

enter image description here

How can I get only the error string without the div?

1

There are 1 best solutions below

1
On

You can get validation error messages from EditContext

<EditForm @ref="_editForm">
...
</EditForm>
@code {
    private EditForm _editForm;
    protected void OnInitialized()
    {
        var editContext = _editForm.EditContext;
        editContext.OnValidationStateChanged += (o, e) =>
        {
             var validationMessages = editContext.GetValidationMessages();
        }
    }
}