Validation is smarter when level level or level level level in asp.net MVC

Validation is more reasonable at what level level or model level in asp.net MVC & amp; also a link of a good tutorial on validation in MVC?

+2


source to share


1 answer


Validation should ALWAYS be done on the client, where possible, and by the server (model in case of MVC.)

ScottGu has a nice blog post on validation in MVC2. Keep in mind that many people have problems with "automatic" client-side validation based on DataAnnotations. You are supposed to add attributes of type [Required] to your Model or ViewModel properties, and the MVC system should automatically emit client-side validators for fields for those properties. In practice, I have not been able to get the job done.



Manually adding jQuery validators actually works. If you are using Ajax.BeginForm () you can set the OnBegin AjaxOptions to the name of your javascript validation function.

+3


source







All Articles