Вы находитесь на странице: 1из 2

Villaflor, Mickey D.

ITMAWE-404

Working with Database in ASP.NET

Data Validation
 ASP.NET MVC integrates validation right into the processing of each
request.
 MVC Framework validates any data that is passed to that controller action,
populating a ModelState object with any validation failures it finds and
passing that object to the controller.
 Controller actions can query the ModelState object to determine whether
the request is valid and react accordingly.
 Developers are free to execute their own logic to discover issues that the
framework does not catch and manually add those errors directly using the
ModelState.AddModelError(string key, string message) method.

A. What is the Data Annotations API?


 It provides a set of .NET attributes that developers can apply to data
object class properties.
 These attributes offer a very declarative way to apply validation rules
directly to a model.

Explanation:

Data Validation is an important aspect in ASP.NET MVC applications. It is


used to check if the user input is valid. ASP.NET MVC provides a set of validation
that is easy-to-use, it is also a powerful way to check for errors and display
messages to the user. The MVC Frameworks also validates any data that received
by the controller action in the ModelState. Controller Actions also helps the
ModelState to know if the users input is valid or have an error. The developers are
also free to add their own logic to know if there is an issues that the framework
doesn’t catch and to help them in recognizing this errors using the
ModelState.AddModelError(string, key, string message) method.

Data Annotations API provides a set of attributes so that the developers can
use and apply data objects class. The attributes offer a declarative way to know if the
inputs are validated in the rules directly to a model.

To understand ModelState, I did some research and states that the


ModelState is a property of a Controller, and can be accessed from those classes
that inherit from System.Web.Mvc.Controller. The ModelState represents a collection
of name and value pairs that were submitted to the server during a POST. It also
contains a collection of error messages for each value submitted. Despite its name, it
doesn't actually know anything about any model classes, it only has names, values,
and errors (Jones, 2019).

Вам также может понравиться