开发者

asp.net MVC 2.0 REST service with FormCollection

开发者 https://www.devze.com 2023-01-06 17:14 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号