Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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# 为什么在请求参数中获取null_C#_Json_Asp.net Web Api_Postman - Fatal编程技术网

C# 为什么在请求参数中获取null

C# 为什么在请求参数中获取null,c#,json,asp.net-web-api,postman,C#,Json,Asp.net Web Api,Postman,下面是我的API public HttpResponseMessage Delete(IEnumerable<int> customerIds) { //api stuff } 但是,如果我按照以下方式更新API,就会捕获值 public HttpResponseMessage Delete(CustomerTO customerIds) { //api stuff } public class CustomerTO { public IEnumerable&

下面是我的API

public HttpResponseMessage Delete(IEnumerable<int> customerIds)
{
    //api stuff
}
但是,如果我按照以下方式更新API,就会捕获值

public HttpResponseMessage Delete(CustomerTO customerIds)
{
    //api stuff
}
public class CustomerTO
{
   public IEnumerable<int> CustomerIds
}
公共HttpResponseMessage删除(CustomerTO CustomerID)
{
//原料药
}
公共类客户
{
公共IEnumerable自定义项
}
如果我这样做,我认为这是一项开销


非常感谢您的帮助/建议。

对于第一个建议,我认为您可能需要这样做:

([FromBody] IEnumerable<int> customerIds)
([FromBody]IEnumerable CustomerID)

问题出在post数据对象中。
您只需在请求数据中传递数组
[1,2,3,4]

您传递的对象具有名为
CustomerID
的属性。您需要传入一个整数数组,
[59,60]
。将
CustomerTO customerId
替换为
public IEnumerable customerId
,或者在json中将
中的“customerId:[69,50]
替换为“customerId:{CutomerId:[69,50]}@亚历克斯:用
IEnumerable customerID
替换
customerID
只会给你原来的版本,不是吗?或者您是否正在考虑替换其他地方(不确定在哪里可以使用
public
关键字,因此尝试猜测您的意思)。另外,我甚至不知道你对第二条评论的想法。这将如何帮助更简单的代码工作?“这不会让事情变得更糟吗?”克里斯,我的错。没有仔细阅读这个问题@Kgn web是一个请求,
HTTPDELETE
one?[FromBody]属性指定值将从body或url的哪个位置来。就是这个方法,你还需要通过邮递员而不是对象发送数组。但是这不是一个有效的json
[1,2,3,4]
为什么它无效,我已经对它进行了测试并且工作得很好是的。我的错误。我道歉。
([FromBody] IEnumerable<int> customerIds)