This documentation is archived and is not being maintained.

DisplayFormatAttribute.NullDisplayText Property

Gets or sets the text that is displayed for a field when the field's value is null.

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

public string NullDisplayText { get; set; }

Property Value

Type: System.String
The text that is displayed for a field when the field's value is null. The default is an empty string (""), which indicates that this property is not set.

Sometimes a data field's value is stored as null values in the source. You can specify custom text to display for data fields that have a null value by setting the NullDisplayText property. If this property is not set, null field values are displayed as empty strings ("").


To convert an empty string field value to a null value, you must set the ConvertEmptyStringToNull property to true.

The following example shows how to use the NullDisplayText to define a caption to display when the data field is null.

// Display the text [Null] when the data field is empty.
// Also, convert empty string to null for storing.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
public object Size;

.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.