Skip to content

Commit ccd95d1

Browse files
tdykstraRon Petrusha
authored andcommitted
Note that you can use String.Format placeholders (#2011)
* Note that you can use string.Format placeholders From dotnet/AspNetCore.Docs#10546 * Add line break * feedback * make vb example consistent with c#
1 parent fe04793 commit ccd95d1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

xml/System.ComponentModel.DataAnnotations/StringLengthAttribute.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
<format type="text/markdown"><![CDATA[
3939
4040
## Remarks
41-
ASP.NET Dynamic Data enables CRUD (Create, Read, Update and Delete) operations in a data model. You can specify the minimum and maximum length of characters for each field when data is being inserted or updated. For character data types, the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MinimumLength%2A> and <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MaximumLength%2A> properties identify the largest number of bytes that are required in order to store a string.
42-
43-
41+
ASP.NET Dynamic Data enables CRUD (Create, Read, Update and Delete) operations in a data model. You can specify the minimum and maximum length of characters for each field when data is being inserted or updated. For character data types, the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MinimumLength%2A> and <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute.MaximumLength%2A> properties identify the largest number of bytes that are required in order to store a string.
42+
43+
You can use [composite formatting](~/docs/standard/base-types/composite-formatting.md) placeholders in the error message:
44+
{0} is the name of the property; {1} is the maximum length; and {2} is the minimum length.
45+
The placeholders correspond to arguments that are passed to the <xref:System.String.Format%2A?displayProperty=nameWithType> method at runtime.
4446
4547
## Examples
4648
The following example shows how to limit the number of characters in a field. This example works with the ThumbnailPhotoFileName field in the Products table in the AdventureWorksLT database. The field is limited 4 characters by applying the <xref:System.ComponentModel.DataAnnotations.StringLengthAttribute> attribute to the partial class that represents the Product entity.
@@ -59,6 +61,10 @@ public class ProductMetadata
5961
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
6062
public object ThumbnailPhotoFileName;
6163
64+
[ScaffoldColumn(true)]
65+
[StringLength(4, ErrorMessage = "The {0} value cannot exceed {1} characters. ")]
66+
public object PhotoFileName;
67+
6268
}
6369
```
6470
@@ -74,6 +80,10 @@ Public Class ProductMetadata
7480
<StringLength(4, ErrorMessage := "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")> _
7581
Public ThumbnailPhotoFileName As Object
7682
83+
<ScaffoldColumn(True)> _
84+
<StringLength(4, ErrorMessage := "The {0} value cannot exceed {1} characters. ")> _
85+
Public PhotoFileName As Object
86+
7787
End Class
7888
```
7989
@@ -267,4 +277,4 @@ End Class
267277
</Docs>
268278
</Member>
269279
</Members>
270-
</Type>
280+
</Type>

0 commit comments

Comments
 (0)