views:

306

answers:

2

Hello there,

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 name 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

A: 

Hi Luddico,

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 : )

SDReyes
A: 

This is a excellent comparison from the validation alternatives -so you can select what is better for you ; )

Includes concrete implementations.

SDReyes