dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.15k stars 9.92k forks source link

[Blazor] Form validation #51575

Open javiercn opened 10 months ago

javiercn commented 10 months ago
pratt33k commented 7 months ago

@javiercn Not sure if this is the right place to ask this but I've a Blazor server project with a Dapper connection to SQL Server, I want to check if a field in my form (using EditForm and DataAnnotations validation) is unique or not.

So, I guess I'll have to do some custom validation (attribute or component), I was thinking a validator component would be best in this case but I'm a bit confused for a Blazor server project (without an API), would it be recommended to do such a validation (unique field) using the example similar to Business logic validation with a validator component or Server validation with a validator component

Provided I want to keep doing the Data Annotations validation for common things like required, regex, etc. when the user tabs out but also add this unique field check when the user submits the form (on other successful validation)

The former example makes more sense but I was worried if it polluted the component too much and I'm using Blazor server .net 8 with global interactivity so use the latter example but that is using APIs and I'm not

Thanks a lot for reading through!