Learn how to leverage .NET's validation framework to validate the models and DTOs sent to your services.
- [Instructor] Web API makes it easy for you…to validate your models and DTOs sent…into your service endpoints…and to return some standard responses…when there is a validation error.…Let's look at how that works now.…If you're familiar with Validation in general in .NET…or in ASP.NET.…Then the way that Web API works will already be familiar.…We use attributes from the…System.ComponentModel.DataAnnotations name space…to mark up our models or DTOs.…And then we ask ASP.NET to validate them for us…using the Model State property of the controller base class.…
Let's validate a DTO that I've already created…for you in the exercise files called Authorize Request DTO.…Notice that it's marked up…with a few data annotation attributes already.…First the required attributes on line 7 and line 11.…And those basically indicate that those values…are required and cannot have a null or empty string value.…Then I've set a min and max length…on each of the properties to be exactly 32 characters long.…
With that DTO in mind,…let's create a new empty Web API controller.…
AuthorJonathan "J." Tower
- Convention-based routing
- Binding your code to an HTTP request
- Validating models
- Using attributes to route requests
- Customizing attribute routes
- Data serialization and model binding
- Error handling
- Using exception filters and exception loggers
- API documentation and testing
- Securing your API
Skill Level Beginner
1. Controllers and Actions
3. Data Serialization and Model Binding
4. Error Handling
5. API Documentation and Testing
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.