0
我有一個DTO對象那樣:發送複雜的DTO到網頁API使用jQuery AJAX
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; }
}
而且我有一個這樣的方法,在Web API:
// POST api/Image/CreateImage
[HttpPost]
[Route("CreateImage")]
public IHttpActionResult CreateImage([FromBody]ImageDto imageDto)
{
if (imageDto == null)
return BadRequest();
return Ok();
}
當我嘗試從jQuery的阿賈克斯送我的DTO,複雜類型的值(PositionDTO,RotationDTO和SizeDTO始終是0.0)
這是使用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"
});
}
我該如何獲得JavaScript中的DTO對象的值,而不是所有複雜值的0.0?其他值很好。
Regards !!