Reputation: 890
I'm hoping people here can give me some ideas on how to properly do this.
Currently I have a ViewModel that I use to render my screen. The View model actually contains the flattened data of several domain models. I've decorated the ViewModel with attributes to do basic validation, but the real validation work happens at the service layer. The problem occurs when there is a validation error at the service layer. The name of the property (i.e. - UserName) doesn't match the entry in the ModelState (i.e. - RegistrationViewModel.UserName).
Does anyone have a recommendation for how to handle this?
Thanks in advance!
Steven
Upvotes: 2
Views: 869
Reputation: 890
this isn't the greatest solution, but in the end I'm relying on my basic client side validation to show the basic field validations, anything that get's past that and is validated in the service shows up in the validation summary.
Upvotes: 0
Reputation: 4120
Maybe not an answer to your question, but this is how I usually approach this:
In the domain model I don't use any validation framework, and I don't use it to give user friendly error messages. I always make sure the model is in a valid state. I throw an exception when an invalid value is set (in property setters). I use the constructors of domain objects to always get them in a valid state when instantiated, by using default values and constructor parameters. Real simple but powerful, because you can always be sure your model is in a valid state. You should unit test your domain objects to be absolutely sure. This approach also works great with orm's.
So I only use fluent validation on the viewmodel to give user friendly messages.
Upvotes: 1