ASP.NET MVC 5 Validation


When I started developing web applications with ASP.NET MVC 5, I struggled a lot about how to create forms, but after some time I am very familiar with these language. This article is basically for beginner level developers to help in web application. This is the third article on ASP.NET MVC 5;  today we study a validation of textboxes in web pages.

Step 1: First we create a new project and choose the ASP.NET Web Application and then press Ok Button; after that we choose empty MVC template and at the bottom we check the MVC checkbox and then press Ok button.

ASP.NET Web Application

Step 2: Now we add the controller by left clicking on your Controller folder in your project and then go to Add items; add the first option, Controller, and then you get this window, and select the Add button; after that set the controller name, which is DefaultController, replace it with HomeControllerand then press Add button.


Step 3: After that follow the same method,  now left click on your Models folder and add class and set name as Employee.cs, and then press Add button. Now your class is added in your project.


Step 4: Now we add one library in our class for validation. Now we add some basic properties of employee to put up validation on it

class for validation

Step 5: Now we move to the HomeController and add view method on it to validate the validation which we put in Employee.cs class.


Step 6:
After add a view you rebuild the project and your project is ready and validated.

Add view

Step 7: After rebuilding the project run it and put the information in it and you see that I put in the data, and my textboxes are fully validated.


Read more articles on ASP.NET: