ValidationResult Constructor (String)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Initializes a new instance of the ValidationResult class with the specified error message.
Namespace: System.ComponentModel.DataAnnotations
Assembly: System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)
Syntax
'Declaration
Public Sub New ( _
errorMessage As String _
)
public ValidationResult(
string errorMessage
)
Parameters
- errorMessage
Type: System.String
The error message to display to the user. If nulla null reference (Nothing in Visual Basic), the GetValidationResult method uses the FormatErrorMessage method to create the error message.
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.
See Also