Skip to content

Composite string placeholders in validation attributes #2047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tdykstra opened this issue Mar 18, 2019 · 2 comments
Open

Composite string placeholders in validation attributes #2047

tdykstra opened this issue Mar 18, 2019 · 2 comments
Labels
area-System.ComponentModel.DataAnnotations help wanted Good for community contributors to help [up-for-grabs] Pri3 Indicates issues/PRs that are low priority
Milestone

Comments

@tdykstra
Copy link
Contributor

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.

@dotnet-bot dotnet-bot added the untriaged New issue has not been triaged by the area owner label Mar 18, 2019
@rpetrusha rpetrusha added 📁 Repo - dotnet-api-docs and removed untriaged New issue has not been triaged by the area owner labels Mar 18, 2019
@rpetrusha rpetrusha added this to the Backlog milestone Mar 18, 2019
@tdykstra tdykstra added easy Issue should be easy to implement, good for first-time contributors help wanted Good for community contributors to help [up-for-grabs] labels Mar 18, 2019
@mairaw mairaw removed the easy Issue should be easy to implement, good for first-time contributors label Apr 4, 2019
@mairaw
Copy link
Contributor

mairaw commented Apr 4, 2019

I've removed the easy label for this one since that is one we use for issues that are beginner-friendly, which doesn't seem to be the case here.

@PRMerger13 PRMerger13 added the Pri3 Indicates issues/PRs that are low priority label Nov 11, 2020
@ghost
Copy link

ghost commented Feb 4, 2022

Tagging subscribers to this area: @ajcvickers
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: tdykstra
Assignees: -
Labels:

:file_folder: Repo - dotnet-api-docs, multiple-topics, up-for-grabs, Pri3, area-System.ComponentModel.DataAnnotations

Milestone: Backlog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.ComponentModel.DataAnnotations help wanted Good for community contributors to help [up-for-grabs] Pri3 Indicates issues/PRs that are low priority
Projects
None yet
Development

No branches or pull requests

7 participants