Blazor Custom ValidationAttribute For Unique Constraint

358 Views Asked by At

I am working in Blazor WASM where my Entity Model classes are in the shared folder so the client and the server can pass instances. API controllers are used to interact with the DB Context, and a Repository pattern in the Client interacts with the controllers through a HttpService. I would like to create a custom ValidationAttribute that leverages client side validation of an Indexed(Unique) property of an entity and flags the InputText before a post/put request can be sent. I already have Entity.HasIndex().IsUnique() setup in OnModelCreating, so this logic is forced on the back end, but I would like to have something in the EditForm. The problem is, the Shared project has no access to the Server project (naturally), so it cannot ping the DB to check for violations. Is there a way around this (maybe by creating a validation attritute that can be applied directly to the front end)?

0

There are 0 best solutions below