Saturday, January 4, 2014

Aspect oriented model validations for WebAPI

We're building a brand new web app with the 'latest and greatest' stuff: MVC5, WebAPI 2 and AngularJS. I was looking for a nice way to do model validation in WebApi and I found this article:

Check it out - it's very elegant. So Angular's $ will do some task and if things work out, you get the 400 statuscode and it'll call the success handler. If not, it'll trigger the error callback and I'm displaying the validation messages. Very clean, very re-usable and very few lines of code.

Works fine with a combination of attribute validations, like [Required] and [Range] with IValidateableObject.

No comments:

Post a Comment