Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DisplayFormatAttribute.ConvertEmptyStringToNull Property

Gets or sets a value that indicates whether empty string values ("") are automatically converted to null.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

public bool ConvertEmptyStringToNull { get; set; }

Property Value

Type: System.Boolean
true if empty string values are automatically converted to null; otherwise, false.

The following example shows how to apply the DisplayFormatAttribute attribute to a property named ListPrice that displays currency values and a property named Size that contains null or empty string values.


public class Product
{
  [DisplayFormat(DataFormatString = "{0:C}")]
  public Decimal ListPrice { get; set; }

  [DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "Not specified.")]
  public string Size { get; set; }
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft