POST在WEB API 2相关的集合,OData的4 [英] POST to a related collection in WEB API 2 with OData 4

查看:238
本文介绍了POST在WEB API 2相关的集合,OData的4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有这样一个路径:

/Accounts(id)/Orders 

在那里我可以执行一个POST来创建订单。我不能找到一种方法,在添加使用的WebAPI的OData这条路线。对于那里是按照获得相关集的惯例,但我无法找到任何约定,发布新实体相关的集合。

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.

有没有来处理与网页API 2和4 OData的?

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

推荐答案

增加了以下属性的方法和它的工作:

Added the following attributes to the method and it worked:

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

}

这篇关于POST在WEB API 2相关的集合,OData的4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆