I have a DTO Object like that:
public class ImageDto : EntityDTO
{
public ImageDto()
{
Position = new PositionDTO();
Rotation = new RotationDTO();
Size = new SizeDTO();
}
public string Name { get; set; }
public string Source { get; set; }
public string Description { get; set; }
public string Style { get; set; }
public string Link { get; set; }
public int ZIndex { get; set; }
public string Effect { get; set; }
public PositionDTO Position { get; set; }
public RotationDTO Rotation { get; set; }
public SizeDTO Size { get; set; }
}
And I have a Web Api with a method like that:
// POST api/Image/CreateImage
[HttpPost]
[Route("CreateImage")]
public IHttpActionResult CreateImage([FromBody]ImageDto imageDto)
{
if (imageDto == null)
return BadRequest();
return Ok();
}
When I try to send my DTO from Jquery Ajax, the values of the complex types (PositionDTO, RotationDTO and SizeDTO are always 0.0)
This is my code using jQuery AJAX:
var urlApi = '/api/Image/CreateImage';
var imageDTO =
{
Name: "",
Source: "",
Description: "",
IdSlide: "9aa2d084-dd82-457b-a80d-9af8375c59ff",
Style: "",
Link: "",
ZIndex: "",
Effect: "",
SizeDTO: {
Width: 200,
Height: 200,
},
PositionDTO: {
PositionLeft: 200,
PositionTop: 200,
},
RotationDTO: { Rotation: 180 },
IdGenially: "54006b50b59f86143834c187"
};
function getData() {
return $.ajax({
url: urlApi,
type: 'POST',
data: JSON.stringify(imageDTO),
contentType: "application/json; charset=utf-8"
});
}
How can I do for obtain the value of the DTO Object in JavaScript and not a 0.0 for all complex values? The other values are coming fine.
Regards!!