Share via


CompareAttribute Class

Provides an attribute that compares two properties of a model.

Inheritance Hierarchy

System.Object
  System.Attribute
    System.ComponentModel.DataAnnotations.ValidationAttribute
      System.Web.Mvc.CompareAttribute

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property)> _
Public Class CompareAttribute _
    Inherits ValidationAttribute _
    Implements IClientValidatable
'Usage
Dim instance As CompareAttribute
[AttributeUsageAttribute(AttributeTargets.Property)]
public class CompareAttribute : ValidationAttribute, 
    IClientValidatable
[AttributeUsageAttribute(AttributeTargets::Property)]
public ref class CompareAttribute : public ValidationAttribute, 
    IClientValidatable
public class CompareAttribute extends ValidationAttribute implements IClientValidatable

The CompareAttribute type exposes the following members.

Constructors

  Name Description
Public method CompareAttribute Initializes a new instance of the CompareAttribute class.

Top

Properties

  Name Description
Public property ErrorMessage (Inherited from ValidationAttribute.)
Public property ErrorMessageResourceName (Inherited from ValidationAttribute.)
Public property ErrorMessageResourceType (Inherited from ValidationAttribute.)
Protected property ErrorMessageString (Inherited from ValidationAttribute.)
Public property OtherProperty Gets the property to compare with the current property.
Public property TypeId (Inherited from Attribute.)

Top

Methods

  Name Description
Public method Equals (Inherited from Attribute.)
Protected method Finalize (Inherited from Object.)
Public method FormatErrorMessage Applies formatting to an error message based on the data field where the compare error occurred. (Overrides ValidationAttribute.FormatErrorMessage(String).)
Public methodStatic member FormatPropertyForClientValidation Formats the property for client validation by prepending an asterisk (*) and a dot.
Public method GetClientValidationRules Gets a list of compare-value client validation rules for the property using the specified model metadata and controller context.
Public method GetHashCode (Inherited from Attribute.)
Public method GetType (Inherited from Object.)
Public method GetValidationResult (Inherited from ValidationAttribute.)
Public method IsDefaultAttribute (Inherited from Attribute.)
Public method IsValid(Object) (Inherited from ValidationAttribute.)
Protected method IsValid(Object, ValidationContext) Determines whether the specified object is equal to the compared object. (Overrides ValidationAttribute.IsValid(Object, ValidationContext).)
Public method Match (Inherited from Attribute.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString (Inherited from Object.)
Public method Validate(Object, String) (Inherited from ValidationAttribute.)
Public method Validate(Object, ValidationContext) (Inherited from ValidationAttribute.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method _Attribute.GetIDsOfNames (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfo (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfoCount (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.Invoke (Inherited from Attribute.)

Top

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Web.Mvc Namespace