Skip to content

Composite string placeholders in validation attributes #2047

Open
@tdykstra

Description

@tdykstra

Many validation attributes compose their error messages using String.Format with one or more arguments. You can use placeholders like {0}, {1}, {2}, etc. in the error message string passed to the attribute. For example:

[StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]

If the property name is "Name" and the maximum length is 25, the error message would be "The Name value cannot exceed 25 characters."

The composite string capability has not been documented for most of the validation attributes. The first one (StringLength) has been done, and that PR #2011 can be used as a template to follow when doing the others.

To find out which parameters are passed to String.Format for a particular attribute's error message, see the DataAnnotations source code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions