System.ComponentModel.DataAnnotations 4.0.0.0 System.ComponentModel.DataAnnotations.ValidationAttribute System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.All, AllowMultiple=false)

The attribute specifies that when a field on a form is validated, the field must contain a value. A validation exception is raised if the property is null, contains an empty string (""), or contains only white-space characters.

If the MVC data model or entity partial class contains a field that is annotated with the attribute, but the page does not contain the property, an error is not raised. Validation occurs only for fields that are submitted to the server.

A Visual Studio project with source code is available to accompany this topic: Download.

Specifies that a data field value is required.

- Constructor
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

- Property
  4.0.0.0
  System.Boolean To be added.

  When you set to true for a data field, Dynamic Data does not perform validation and transforms the empty string to a null value. This value is then passed to the database.

  If the database does not allow null values, it raises an error. To avoid this error, you must also set the to false.

  Gets or sets a value that indicates whether an empty string is allowed.

- Method
  4.0.0.0
  System.Boolean ``

  If the value is an empty string, the method returns false and a validation error is displayed.

  Checks that the value of the required data field is not empty.

  true if validation is successful; otherwise, false.

  The data field value to validate.