[英]Not able to pass JSON object from Rest Client to MVC4 controller C#
I am calling the Controller action from Postman RestClient and passing the object but I am receiving values as 0. 我从Postman RestClient调用Controller动作并传递对象,但我收到的值为0。
Request URL : http://localhost:27266/ImageProcessing/CreateThumbnail
要求网址: http://localhost:27266/ImageProcessing/CreateThumbnail
POST data : 发布数据 :
{
"data":{
"Width":140
"Height":140
}
}
to 至
[HttpPost]
[ValidateInput(false)]
public JsonResult CreateThumbnail(InputDataModel data )
{
return Json(new { Height = "0"});
}
where InputDataModel is 其中InputDataModel是
public class InputDataModel
{
public int Width { get; set; }
public int Height { get; set; }
}
I am receiving Width and Height as 0. 我收到的宽度和高度为0。
Am I missing anything.? 我错过了什么吗?
I don't think the mapper will trawl the whole object tree to map - it needs to be told where to look, for example: 我不认为映射器会将整个对象树拖网映射 - 需要告诉它在哪里看,例如:
public class YourModel
{
public InputDataModel data { get; set; }
}
public class InputDataModel
{
public int Width { get; set; }
public int Height { get; set; }
}
Or you can adjust the JSON to conform to the InputDataModel
, so it should have two members named Width
and Height
... not nested inside the data
property. 或者您可以调整JSON以符合InputDataModel
,因此它应该有两个名为Width
和Height
成员...不嵌套在data
属性中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.