Поделиться через


ValidationResult.Success Field

Microsoft Silverlight will reach end of support after October 2021. Learn more.

A value that indicates the entity member successfully validated.

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

Syntax

'Declaration
Public Shared ReadOnly Success As ValidationResult
public static readonly ValidationResult Success

Examples

The following example shows how to return a validation result that indicates success or failure.

Imports System.ComponentModel.DataAnnotations

Public Class AWValidation
  Public Shared Function ValidateSalesPerson(salesPerson As String) As ValidationResult
    Dim isValid As Boolean

    ' Perform validation logic here and set isValid to true or false.

    If (IsValid) Then
      ValidateSalesPerson = ValidationResult.Success
    Else
      ValidateSalesPerson = New ValidationResult( _
          "The selected sales person is not available for this customer.")
    End If
    End Function

  Public Shared Function ValidateAddress(addressToValidate As CustomerAddress) As ValidationResult
    Dim isValid As Boolean

    ' Perform validation logic here and set isValid to true or false.

    If (IsValid) Then
      ValidateAddress = ValidationResult.Success
    Else
      ValidateAddress = New ValidationResult( _
          "The address for this customer does not match the required criteria.")
    End If
  End Function
End Class
using System.ComponentModel.DataAnnotations;

public class AWValidation
{
  public static ValidationResult ValidateSalesPerson(string salesPerson)
  {
    bool isValid;

    // Perform validation logic here and set isValid to true or false.

    if (isValid)
    {
      return ValidationResult.Success;
    }
    else
    {
      return new ValidationResult(
          "The selected sales person is not available for this customer.");
    }
  }

  public static ValidationResult ValidateAddress(CustomerAddress addressToValidate)
  {
    bool isValid;

    // Perform validation logic here and set isValid to true or false.

    if (isValid)
    {
      return ValidationResult.Success;
    }
    else
    {
      return new ValidationResult(
          "The address for this customer does not match the required criteria.");
    }
  }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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