The Remote Attribute

In this lesson, we will learn how to use the `RemoteAttribute` that performs a client-side validation by issuing an AJAX call to the server.

There are situations when an input must be validated as soon as it is provided, but the information needed for the validation is available only on the server-side. A common example is the validation of unique identifiers chosen by the user, such as an email address, a username, or the subdomain name for a blog or any other personal set of pages.

It is important to furnish immediate feedback on the availability of the name so that the user can easily check several names till they find an available name they like. The verification requires a check on the server’s permanent storage.

The RemoteAttribute was conceived to face situations like the ones depicted above. While all other validation attributes are part of the standard .NET set of validation facilities and are all placed in the System.ComponentModel.DataAnnotations namespace, the RemoteAttribute was conceived specifically for Web applications, so it is located in an ASP.NET Core library under the Microsoft.AspNetCore.Mvc namespace.

RemoteAttribute usage

Basic usage of the RemoteAttribute is quite simple, we need to pass just the action method name and the controller name of the server validation endpoint as arguments:

Get hands-on with 1400+ tech skills courses.