The solution has a data entities project and an ASP.NET Core 3.1 MVC project using EF Core.
In the data entities project, there is a domain class:
public class BoatMaker
{
[Key]
public int Id { get; set; }
[Required]
public string Name {get; set;}
}
I want to be able to decorate this like this:
[Required]
[Unique]
public string Name {get; set;}
so that the model will be invalid if the name is already in the database, and the validation error message automatically populated to that effect in the data validation in the view.
How can this be achieved? Can it be done?
The project uses the repository model, injected into the controllers. The DbContext is obvs. in the web project.
asyncsupport. So either you need to design your own validation pipeline (not usingValidationAttributebecause it does not supportasync) or you can also useRemoteAttributefor the purpose of validating a property. I personally think it's not a good design because it depends on your api endpoint, not your service api. It requires you to expose an end point for validating. Here is the link to how you can use it learn.microsoft.com/en-us/aspnet/core/mvc/models/…