C# 使用jquery ajax将复杂的DTO发送到web api

C# 使用jquery ajax将复杂的DTO发送到web api,c#,jquery,ajax,asp.net-web-api,C#,Jquery,Ajax,Asp.net Web Api,我有这样一个DTO对象: public class ImageDto : EntityDTO { public ImageDto() { Position = new PositionDTO(); Rotation = new RotationDTO(); Size = new SizeDTO(); } public string Name { get; set; } public string Sourc

我有这样一个DTO对象:

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; }

}
    // POST api/Image/CreateImage
    [HttpPost]
    [Route("CreateImage")]
    public IHttpActionResult CreateImage([FromBody]ImageDto imageDto)
    {
        if (imageDto == null)
            return BadRequest();

        return Ok();

    }
我有一个Web Api,其方法如下:

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; }

}
    // POST api/Image/CreateImage
    [HttpPost]
    [Route("CreateImage")]
    public IHttpActionResult CreateImage([FromBody]ImageDto imageDto)
    {
        if (imageDto == null)
            return BadRequest();

        return Ok();

    }
当我尝试从Jquery Ajax发送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?其他价值观都很好


问候

您的类没有*DTO属性,您的属性是:
位置
旋转
大小

public PositionDTO Position { get; set; }
public RotationDTO Rotation { get; set; }
public SizeDTO Size { get; set; }
尝试从您的姓名中删除DTO:

    Size: {
        Width: 200,
        Height: 200,
    },
    Position: {
        PositionLeft: 200,
        PositionTop: 200,
    },

    Rotation: { Rotation: 180 },