I am calling the Controller action from Postman RestClient and passing the object but I am receiving values as 0.
Request URL : 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
public class InputDataModel
{
public int Width { get; set; }
public int Height { get; set; }
}
I am receiving Width and Height as 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.