This project is read-only.

How to validate models when posting?

Topics: Web Api
Nov 2, 2011 at 10:11 PM

I have a set of services hosted with WCF Web Api, what I need to do is validate the properties inside the models of the app.

In MVC 3 for example I decorate properties in the model like this:

public string UserName { get; set; }

and then in the controller I proceed like this to verify os the model has met the validation parameters:

ActionResult Create(Model myModel)
Post the model
Don't post the model
Is there a way to do something similar in WCF Web Api?

Nov 2, 2011 at 11:55 PM

We don’t currently support model validation based on data annotations, but this is certainly something that we are looking at supporting in a future release.

Do you want to open an Issue Tracker item for this so that the community can vote on this feature?

You could also take a look at implementation validation yourself using the Validator APIs in System.ComponentModel.DataAnnotations.

Daniel Roth