ASP.NET MVC Input Validation
Validation of user input is necessary task for the application programmer. An application should allow only valid user input so that we get only desired information.
ASP.NET MVC framework provides built-in annotations that we can apply on Model properties. It validates input and display appropriate message to the user.
Commonly used Validation Annotations
Let's create an example that will validate input by using the annotations. To create the example, first we are creating a StudentsController and then a Student Model.
To see the output, right click on the Index.cshtml file and select view in browser. This will produce the following result.
As we can see that it validates form fields and display error message to the user. In the below screenshot, we are validating that the entered data is as expected.