Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加实体列表作为参数_C#_Asp.net Web Api_Odata_Asp.net Web Api Odata - Fatal编程技术网

C# 添加实体列表作为参数

C# 添加实体列表作为参数,c#,asp.net-web-api,odata,asp.net-web-api-odata,C#,Asp.net Web Api,Odata,Asp.net Web Api Odata,是否可以检索实体列表作为c#odata中操作的参数 尝试了以下操作,但导致整个控制器无法工作: [HttpPost] [NhSessionManagement()] [ODataRoute("BatchUpdate")] public async Task<IHttpActionResult> BatchUpdate(List<Item> items, bool updateDefaultJSONFile) { return Ok(); } 在《小提琴手》中:

是否可以检索实体列表作为c#odata中操作的参数

尝试了以下操作,但导致整个控制器无法工作:

[HttpPost]
[NhSessionManagement()]
[ODataRoute("BatchUpdate")]
public async Task<IHttpActionResult> BatchUpdate(List<Item> items, bool updateDefaultJSONFile)
{
    return Ok();
}
在《小提琴手》中:

POST http://192.168.20.108/api/items/Service.BatchUpdate HTTP/1.1
Host: 192.168.20.108
Connection: keep-alive
Content-Length: 83114
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
Origin: http://192.168.20.108
Authorization: Bearer ****
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://192.168.20.108/
Accept-Encoding: gzip, deflate
Accept-Language: sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7

{"items":[{"Key":"helpful","Text":"test"}],"updateDefaultJSONFile":false}

将集合参数指定为数组,而不是列表:

[HttpPost]
[NhSessionManagement()]
[ODataRoute("BatchUpdate")]
public async Task<IHttpActionResult> BatchUpdate(Item[] items, bool updateDefaultJSONFile)
{
    return Ok();
}
[HttpPost]
[NhSessionManagement()]
[ODataRoute(“批次更新”)]
公共异步任务BatchUpdate(项[]项,bool updateDefaultJSONFile)
{
返回Ok();
}

配置正确,干得好。

谢谢您的帮助。现在控制器似乎正在工作。但他的行动并非如此。这些参数出现404错误,没有任何参数,我的调用正在工作,因此可能与我发送和接收数据的方式不匹配。
POST http://192.168.20.108/api/items/Service.BatchUpdate HTTP/1.1
Host: 192.168.20.108
Connection: keep-alive
Content-Length: 83114
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
Origin: http://192.168.20.108
Authorization: Bearer ****
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://192.168.20.108/
Accept-Encoding: gzip, deflate
Accept-Language: sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7

{"items":[{"Key":"helpful","Text":"test"}],"updateDefaultJSONFile":false}
[HttpPost]
[NhSessionManagement()]
[ODataRoute("BatchUpdate")]
public async Task<IHttpActionResult> BatchUpdate(Item[] items, bool updateDefaultJSONFile)
{
    return Ok();
}