dotnet / dotnet/AspNetCore.Docs
Does ModelState.IsValid evaluated on a Movie object validate Genre against its own validation attributes?
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
Description
### Description
What I was wondering is whether ModelState.IsValid evaluated on a Movie object would also validate its Genre property value against any validation attributes on the Genre class itself. From my testing it appears the answer is no. It would be helpful to note this in the documentation and perhaps to provide an example where if you want to validate the Genre property value against the Genre class validation attributes you could, for example, use TryValidateModel(movie.Genre, nameof(Genre)) instead.
### Page URL
https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-8.0
### Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/mvc/models/validation.md
### Document ID
615db388-a244-41f7-21b5-a4085d9ed479
### Article author
@Rick-Anderson
Contributor guide
Assessment
This issue has not been assessed yet.