Validator.TryValidateValue Method

Determines whether a specified value is valid against a collection of validation attributes.

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

public static bool TryValidateValue(
	Object value,
	ValidationContext validationContext,
	ICollection<ValidationResult> validationResults,
	IEnumerable<ValidationAttribute> validationAttributes


Type: System.Object
The value to validate.
Type: System.ComponentModel.DataAnnotations.ValidationContext
An object that contains information about the validation request.
Type: System.Collections.Generic.ICollection<ValidationResult>
A collection to store validation results.
Type: System.Collections.Generic.IEnumerable<ValidationAttribute>
The collection of validation attributes to use to determine if value is valid.

Return Value

Type: System.Boolean
true if value is valid against the validation attributes; otherwise, false.

The TryValidateValue method tests each validation attribute in the validationAttributes parameter against the value parameter. If a RequiredAttribute attribute is included, the RequiredAttribute attribute is evaluated first.

If validationResults is null, the method stops at the first validation failure. If validationResults is not null, the method evaluates all validation attributes and adds all of the failures to validationResults.


Supported in: 5, 4, 3

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

Community Additions