Where to introduce data management rules for comprehensive data validation in ASP.NET MVC?

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.

+3
source share
3 answers

Mega Dupe. Mega Subjective. " MVC" , . /, .

, . . , (someString!= "") ?;)

, , . , Driven Design , , .

? ,

ASP.NET MVC 2 DTO

ASP.Net MVC 2 ?

DTO

ASP.NET MVC?

ASP.NET MVC - / - ?

ASP.NET MVC: ?

MVC - ( )?

ASP.NET MVC

DDD:

+4

, ( ).

, , , Required, Regex ..

- - -.

, MVC, - , Validate(), , - .., Save();

+2

Once you have a filled class that is ready for verification, just pass it to the verification class in the controller.

+1
source

All Articles