asp.net MVC 2.0 REST service with FormCollection
Let's say the Action below is exposed via REST service and is called from a different appliation how would it handle the posted data/object?
Should 开发者_开发技巧I use Create(FormCollection collection) here?
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Member member) { .... }
I'd suggest using a model, but one in which all of the parameters are nullable and use the RequiredAttribute for actual, required parameters. This would allow your method to accept invalid requests -- with missing or extra data -- yet have valid data bound to the model. For invalid data, you can supply error returns instead of presuming default values for non-nullable properties. Using the model binding validation architecture provides a convenient way to make sure that the request is legal. It would be up to you how you want to handle "extra" data supplied by the request -- I'd say ignore it.
精彩评论