Export (0) Print
Expand All

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
)

Parameters

value
Type: System.Object
The value to validate.
validationContext
Type: System.ComponentModel.DataAnnotations.ValidationContext
An object that contains information about the validation request.
validationResults
Type: System.Collections.Generic.ICollection<ValidationResult>
A collection to store validation results.
validationAttributes
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.

Silverlight

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

ADD
Show:
© 2014 Microsoft