Search code examples
blazorblazor-webassembly

Got someone Blazor remote validation to work?


I tried to get remote validation with Blazor working. There are currently no Blazor Examples in the Internet.

I configured my controller / remote attribute like described in the documentation:

https://learn.microsoft.com/de-de/aspnet/core/mvc/models/validation?view=aspnetcore-3.1#remote-attribute

My blazor code looks like this

<EditForm EditContext="@_editContext" > 
   <ObjectGraphDataAnnotationsValidator/>
   <ValidationMessage  For="@(() => User.Email)"/>
   <InputText class="text" type="text" placeholder="Email*" @bind Value="User.Email"/>
</EditForm>

I got no errors. There is no request going out and no validation is gonna be executed.

Dont know whats missing.


Solution

  • You can't use DataAnnotation Remote attribute with Blazor. You may use FluentValidation instead. Here's a link to an article explaining how to do that.

    Note: This @bind Value="User.Email" should be @bind-Value="User.Email"

    Hope this works...