ASP.NET MVC - Model Validation regarding its dataType Length
I'm using ASP.NET MVC 1 on a project where I would like to validate my form submission with the ModelBinding helpers, actually I am validating it with ModelState.IsValid but it doesn't seem to consider the dataType length when validating it. For example:
I have a field nvarchar(70) called Name , but when in my form I submit a na开发者_JS百科me with 200 chars, it pass the validation anyways...anyone knows how to prevent this to happen and make the modelBinding respect the datatype length?
Thanks in advance
Update: Thanks for the help till now: I'm using just standard Linq associations and modelBinding to validate the models, I hope this can help somehow Cheers
This is a excellent comparison from the validation alternatives -so you can select what is better for you ; )
Includes concrete implementations.
I recommend you to keep your model validation logic out of the binding module. and just feed your ModelState with the validation errors from inside your service layer.
See this series from the ASP.Net MVC page for examples : )
精彩评论