Class RemoteAttribute
Provides an attribute that uses the jQuery validation plug-in remote validator.
[AttributeUsage(AttributeTargets.Property)]
public class RemoteAttribute : ValidationAttribute, IClientValidatable
- Inheritance
-
RemoteAttribute
- Implements
- Inherited Members
Constructors
RemoteAttribute()
Initializes a new instance of the RemoteAttribute class.
protected RemoteAttribute()
RemoteAttribute(string)
Initializes a new instance of the RemoteAttribute class using the specified route name.
public RemoteAttribute(string routeName)
Parameters
routeName
stringThe route name.
RemoteAttribute(string, string)
Initializes a new instance of the RemoteAttribute class using the specified action-method name and controller name.
public RemoteAttribute(string action, string controller)
Parameters
RemoteAttribute(string, string, string)
Initializes a new instance of the RemoteAttribute class using the specified action-method name, controller name, and area name.
public RemoteAttribute(string action, string controller, string areaName)
Parameters
action
stringThe name of the action method.
controller
stringThe name of the controller.
areaName
stringThe name of the area.
RemoteAttribute(string, string, AreaReference)
Initializes a new instance of the RemoteAttribute class.
public RemoteAttribute(string action, string controller, AreaReference areaReference)
Parameters
action
stringThe route name.
controller
stringThe name of the controller.
areaReference
AreaReferenceFind the controller in the root if UseRoot. Otherwise look in the current area.
Properties
AdditionalFields
Gets or sets the additional fields that are required for validation.
public string AdditionalFields { get; set; }
Property Value
- string
The additional fields that are required for validation.
HttpMethod
Gets or sets the HTTP method used for remote validation.
public string HttpMethod { get; set; }
Property Value
- string
The HTTP method used for remote validation. The default value is "Get".
RouteData
Gets the route data dictionary.
protected RouteValueDictionary RouteData { get; }
Property Value
- RouteValueDictionary
The route data dictionary.
RouteName
Gets or sets the route name.
protected string RouteName { get; set; }
Property Value
- string
The route name.
Routes
Gets the route collection from the route table.
protected virtual RouteCollection Routes { get; }
Property Value
- RouteCollection
The route collection from the route table.
Methods
FormatAdditionalFieldsForClientValidation(string)
Returns a comma-delimited string of validation field names.
public string FormatAdditionalFieldsForClientValidation(string property)
Parameters
property
stringThe name of the validation property.
Returns
- string
A comma-delimited string of validation field names.
FormatErrorMessage(string)
Formats the error message that is displayed when validation fails.
public override string FormatErrorMessage(string name)
Parameters
name
stringA name to display with the error message.
Returns
- string
A formatted error message.
FormatPropertyForClientValidation(string)
Formats the property for client validation by prepending an asterisk (*) and a dot.
public static string FormatPropertyForClientValidation(string property)
Parameters
property
stringThe property.
Returns
- string
The string "*." Is prepended to the property.
GetClientValidationRules(ModelMetadata, ControllerContext)
Gets a list of client validation rules for the property.
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
Parameters
metadata
ModelMetadataThe model metadata.
context
ControllerContextThe controller context.
Returns
- IEnumerable<ModelClientValidationRule>
A list of remote client validation rules for the property.
GetUrl(ControllerContext)
Gets the URL for the remote validation call.
protected virtual string GetUrl(ControllerContext controllerContext)
Parameters
controllerContext
ControllerContextThe controller context.
Returns
- string
The URL for the remote validation call.
IsValid(object)
This method always returns true.
public override bool IsValid(object value)
Parameters
value
objectThe validation target.
Returns
- bool
true