Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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
无法将JSON对象从Rest客户端传递到MVC4控制器C#_C#_Json_Asp.net Mvc 4 - Fatal编程技术网

无法将JSON对象从Rest客户端传递到MVC4控制器C#

无法将JSON对象从Rest客户端传递到MVC4控制器C#,c#,json,asp.net-mvc-4,C#,Json,Asp.net Mvc 4,我正在从Postman RestClient调用控制器操作并传递对象,但我收到的值为0 请求URL:http://localhost:27266/ImageProcessing/CreateThumbnail 发布数据: { "data":{ "Width":140 "Height":140 } } 到 InputDataModel在哪里 public class InputDataModel { public int Width { get; set;

我正在从Postman RestClient调用控制器操作并传递对象,但我收到的值为0

请求URL:
http://localhost:27266/ImageProcessing/CreateThumbnail

发布数据:

{
"data":{
    "Width":140
    "Height":140
    }
}   

InputDataModel在哪里

public class InputDataModel 
{
    public int Width { get; set; }

    public int Height { get; set; }
}
我收到的宽度和高度为0


我遗漏了什么吗?

我不认为映射器会拖网整个对象树来映射-需要告诉它在哪里查找,例如:

public class YourModel
{
    public InputDataModel data { get; set; }
}

public class InputDataModel 
{
    public int Width { get; set; }

    public int Height { get; set; }
}

或者您可以调整JSON以符合
InputDataModel
,因此它应该有两个名为
Width
Height
的成员。。。未嵌套在
数据
属性中。

我认为映射器不会拖网整个对象树进行映射-需要告诉它在哪里查找,例如:

public class YourModel
{
    public InputDataModel data { get; set; }
}

public class InputDataModel 
{
    public int Width { get; set; }

    public int Height { get; set; }
}

或者您可以调整JSON以符合
InputDataModel
,因此它应该有两个名为
Width
Height
的成员。。。未嵌套在
数据
属性中。

仅尝试此部分
{“Width”:140“Height”:140}
。您说接收到空对象,然后说高度和宽度为0。是哪一个?@bigdady:我更正了,因为int是不可为null的,所以我得到了0。我想@JSantosh的回答可能就是答案,你为什么不使用传入的对象?@JSantosh这也不起作用。试试这个部分
{“Width”:140“Height”:140}
。你说你收到了一个null对象,然后你说高度和宽度是0。是哪一个?@bigdady:我更正了,因为int是不可为空的,所以我得到了0。我想@JSantosh的回答可能就是答案,你为什么不使用传入的对象?@JSantosh这也不起作用。你能分享实际的POST请求吗?也许它缺少适当的内容类型来告诉服务器它正在发送JSON?您可以共享实际的POST请求吗?也许它缺少适当的内容类型来告诉服务器它正在发送JSON?