Skip to content

Commit

Permalink
Specified where attributes can be applied (#9204)
Browse files Browse the repository at this point in the history
Fixes #8574
  • Loading branch information
daveabrock authored and Rick-Anderson committed Oct 24, 2018
1 parent 995514f commit e4a189b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aspnetcore/mvc/models/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Fortunately, .NET has abstracted validation into validation attributes. These at

Validation attributes are a way to configure model validation so it's similar conceptually to validation on fields in database tables. This includes constraints such as assigning data types or required fields. Other types of validation include applying patterns to data to enforce business rules, such as a credit card, phone number, or email address. Validation attributes make enforcing these requirements much simpler and easier to use.

Validation attributes are specified at the property level:

```csharp
[Required]
public string MyProperty { get; set; }
```

Below is an annotated `Movie` model from an app that stores information about movies and TV shows. Most of the properties are required and several string properties have length requirements. Additionally, there's a numeric range restriction in place for the `Price` property from 0 to $999.99, along with a custom validation attribute.

[!code-csharp[](validation/sample/Movie.cs?range=6-29)]
Expand Down

0 comments on commit e4a189b

Please sign in to comment.