Skip to content

Describe Composite Formatting of ValidationAttribute ErrorMessages  #10546

@Rick-Anderson

Description

@Rick-Anderson

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:

https://github.com/aspnet/Docs/blob/4dad08a6662a5cf2eac03c46b4dbb2cd009a43ef/aspnetcore/fundamentals/localization/sample/Localization/ViewModels/Account/RegisterViewModel.cs#L16-L20

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:


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions