I am currently working on an ASP.NET MVC2 project. This is the first time I'm working on a real MVC web application. The ASP.NET MVC website really helped me get started very quickly, but I still have some vague knowledge regarding data validation.
My problem is that I really don't know where to manage my populated date when it comes to complicated validation rules. For example, checking a string field with Regex is quite simple, and I know that I just need to decorate my field with a specific attribute, so the data management rules are implemented in the model. But if I have several fields that I need to check, which to each other, for example, several datetimes that should be set correctly after a certain time rule, where do I need to check them? I know that I can create my own validation attributes, but sometimes validation sets a specific validation path that should be difficult to validate using attributes.
This first question also leads me to a related question, which is, is it correct to approve the model in the controller? Because at the moment this is the only way I found for a comprehensive check. But I find it a little dirty, and I feel that it really does not match the role of the controller and is much harder to check (several code paths).
Thank.
NB: I have some pretty good solutions here, but I'm waiting for other ideas and some โbest practiceโ solutions.
source
share