Table of Contents

Class RemoteAttribute

Namespace
System.Web.Mvc
Assembly
System.Web.Mvc.dll

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 string

The 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

action string

The name of the action method.

controller string

The name of the controller.

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 string

The name of the action method.

controller string

The name of the controller.

areaName string

The 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 string

The route name.

controller string

The name of the controller.

areaReference AreaReference

Find 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 string

The 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 string

A 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 string

The 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 ModelMetadata

The model metadata.

context ControllerContext

The 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 ControllerContext

The 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 object

The validation target.

Returns

bool

true