Total Page Preview:   000000000165

What is Remote Validation in ASP.NET Core MVC

 Remote validation 

Remote validation in ASP.NET Core MVC is used to perform server-side validation that requires an asynchronous call to the server. It's typically used when you need to validate user input based on values that are not available on the client side. For example, checking if a username or email already exists in the database.

Here's an example that demonstrates how to use remote validation in ASP.NET Core MVC.
Assuming you have a model class named User:
In this example, the Username property is decorated with the [Remote] attribute, which specifies the action method and controller responsible for performing the validation.
Next, create a controller named ValidationController with an action method named VerifyUsername:
In this VerifyUsername action method, you can implement the logic to check if the provided username already exists in the database or any other external data source.
Make sure to include the necessary scripts in your layout file (_Layout.cshtml) to enable unobtrusive Ajax, which is required for remote validation:
<script src=""></script>
<script src=""></script>
<script src=""></script>
With this set up, when a user enters a username in a form, the remote validation will trigger an asynchronous call to the VerifyUsername action method in the ValidationController to check if the username already exists. If it does, an appropriate error message will be displayed to the user.

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn :





Facebook User: