Validation

Apr 14, 2011 at 2:09 PM

Hi,

Please correct me if my understanding about the validation of the data is right. As from the rev 6, there are >

1. data models - Data models are something that represents the db, defined in MileageStats.Model
2. service models (Domain models) - Used by the controller to interface with business services, defined
3. view models - As the form of data exchange between the UI and the controller?, defined in MileageStats.Web.Models

Model conversions in the service layer is used to convert the service models to data models and vice versa?, so the model is validated before commiting to the db. The service model has data annotations of Stringlength, Required, Range, etc that suggests that validation is done on the service model. But when? As there is no explicit call, when is the validation implicitly called for?

Thanks,
Sawan

Developer
Apr 28, 2011 at 10:29 PM

ASP.NET MVC calls the validation before controller actions are called (I believe it occurs during model binding but am not 100% positive). This allows the usage of the ModelState.IsValid method early in controller actions.

For more information, check out http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx.  This post is for ASP.NET MVC 2, but a lot of the information about how things work is still valid.