Implement remote validation(server side) in asp.net mvc 5

In this tutorial i am going to explain about how to Implement remote validation(server side) in asp.net mvc 5. In my previous tutorial i have explained about

Implementation :

Now we will see the implementation of how to Implement remote validation(server side) in asp.net mvc 5.

First open visual studio and create a new project with mvc template like below and name it as RemoteValidation.

Step 1 of Implement remote validation(server side) in asp.net mvc 5

Once the project is loaded right click on model folder and add User model. Add the below code in the User model.


Now right click on the controller folder add a new empty controller and name it as UserController. Add the below code in the controller.

C#.Net:

VB.Net:

The controller contains the IsUserNameAlreadyExist method which will accept username as input and check whether the username exists in the user list. This method will be used to call in the Remote validation attribute.  Now open the User model class and add Remote validation attribute to Username attribute. The modified code is given below.

C#.Net:

VB.Net:

 

Now add view to AddUser action method. below is the AddUser.cshtml file code.

Output:

Now if you run the program you can see the output of how to Implement remote validation(server side) in asp.net mvc 5. If you enter the username from user1 to user4 then it will show the error message as Username already exists. Else it will accept.

Output of Implement remote validation(server side) in asp.net mvc 5

Source Code:

You can download the Source code of how to Implement remote validation(server side) in asp.net mvc 5 from the below download link.

Source code of how to Implement remote validation(server side) in asp.net mvc 5

 

 

 

Conclusion:

Hope you learned how to Implement remote validation(server side) in asp.net mvc 5. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!