-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Moved from #4505 by @Rabadash8820
It recently came to my attention that ValidationAttribute
error messages support composite formatting. I discovered this while reading about localization of DataAnnotations. That section references a sample code snippet from this repo with the follow property declaration:
The [StringLength]
attribute is what caught my eye; I'd never seen anything like that! A composite format string in an attribute constructor??
Unfortunately, I could not find the parameters for these composite format strings anywhere in the Docs, and had to resort to digging through the .NET Core source code to find how these strings were actually used (usually in string.Format()
calls inside overriden FormatErrorMessage()
calls). It really seems like this information should be documented somewhere other than XML comments in the source code.
Possible TOC locations:
- Introduction to model validation
- Introduction to using tag helpers in forms
- Adding validation
- Part 6: Using Data Annotations for Model Validation
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 0156ffc3-47ac-d5da-fbc2-9ff5018b071b
- Version Independent ID: 615db388-a244-41f7-21b5-a4085d9ed479
- Content: Model validation in ASP.NET Core MVC
- Content Source: aspnetcore/mvc/models/validation.md
- Product: aspnet-core
- GitHub Login: @tdykstra
- Microsoft Alias: riande