POST to a related collection in WEB API 2 with OData 4

我们两清 提交于 2019-12-10 17:22:39

问题


I want to have a route like:

/Accounts(id)/Orders 

where I can execute a POST to create an order. I can't find a way to add this route using OData in WebApi. For GET there is a convention to follow to get related collections, but I am not able to find any convention for posting new entities to a related collection.

Is there a standard way to handle this POST request with Web API 2 and OData 4 ?


回答1:


Added the following attributes to the method and it worked:

[HttpPost]
[ODataRoute("Accounts({key})/Orders")]
public IHttpActionResult Orders([FromODataUri] string key, OrderDto orderDto)
{

}


来源:https://stackoverflow.com/questions/27506627/post-to-a-related-collection-in-web-api-2-with-odata-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!