This documentation is archived and is not being maintained.

DisplayFormatAttribute.ConvertEmptyStringToNull Property

Gets or sets a value that indicates whether empty string values ("") are automatically converted to null when the data field is updated in the data source.

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 default is true.

Users might enter an empty string for a field value. Use the ConvertEmptyStringToNull property to specify whether an empty string value is automatically converted to null when the data field is updated in the database.

NoteNote

By default, a DynamicField object displays null values as empty strings. To display a different value, set the NullDisplayText property.

The following example shows how to use the ConvertEmptyStringToNull to enable the conversion of empty string values to 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.
Show: