Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Composite string placeholders in validation attributes #2047

Copy link
Copy link
Open
@tdykstra

Description

@tdykstra
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.