In addition, you can read more about Data Annotations for model validation in ASP.NET Core.
- Home
- .NET code examples
- Data Annotation custom validator in ASP.NET Core
Data Annotation custom validator in ASP.NET Core
Data Annotations can be used in ASP.NET Core MVC and Web API as a model validator.
System.ComponentModel.DataAnnotations, a custom Data Annotation validator can be created.
CustomerModel model which gets passed in as an endpoint in the CustomerController.
Software
This is the software that will need to be installed onto your machine.
- Visual Studio 2022 version 17.4.4 or above. It will work with the free community version.
- .NET 7 SDK version 7.0.2 or above. Visual Studio 2022 should already have the .NET SDK installed.
Get the application working
These are the steps to get the application working.
- Fill out the code example form. We will send you an email where you can download the code example.
You are now ready to go.
Open the project in Visual Studio
Open up RoundTheCode.DA.sln in Visual Studio 2022.
https://localhost:7001/swagger, and test out the customer API endpoint.
More information
Watch our video where we go ahead and talk through this custom Data Annotation validator and test it out in an ASP.NET Core Web API.
Give us your anonymous feedback regarding this page, or any other areas of the website.
Watch .NET tutorials
Subscribe to our YouTube channel
Latest code examples
C# 14: New features with code examples
Download the code example and see what's new in C# 14. From extension members to simple lambdas, learn how these features make your code cleaner and smarter.