1

I'm trying to pass parameters to a C# method through a post request. I have one C# object that contains all the fields I'm sending with the request and of them is a non primitive object I created. When I send a POST request with the object in a JSON notation, all the other fields are passed correctly but that one - which becomes null.

I'm using the [FromBody] attribute so I tried to go without it and still that property becomes null.

This is my JSON, with my fields name cut out:

{
    "cId": 12,
    "startDate": "2017-01-01 12:00:00",
    "endDate": "2018-01-01 19:00:00",
    "isActive": 1,
    "cType": 1,
    "targetItemCount": 10,
    "targetPayedCount": 100,
    "uses": 50,
    "items": [10, 11, 12],
        "info":
             {
            "InfoId": "00001273-9018-401b-92c1-729a3f895c0f",
            "Barcode": "123123",
            "Status": null,
            "ImageUrl": "urll",
            "Name": "name",
            "Text1": "text1",
            "Text2": "text2",
            "DiscountText": "distext",
            "Price": 10
        } 
}

And my methods signature is:

 [HttpPost]
        public bool DaMethod([FromBody]DaObject Da)

The class DaObject:

public class DaObject
{
    public int cId { get; set; }
    public string startDate { get; set; } 
    public string endDate { get; set; } 
    public bool isActive { get; set; }
    public short cType { get; set; }
    public short targetItemCount { get; set; }
    public short targetPayedCount { get; set; }
    public int uses { get; set; }
    public List<int> items { get; set; }
    public Info info { get; set; }
}

The Info object inside looks like this:

[Serializable]
public class Info
{
    [DataMember]
    public Guid InfoId { get; set; }
    [DataMember]
    public string Barcode { get; set; }
    [DataMember]
    public eStatus Status { get; set; }
    [DataMember]
    public string ImageUrl { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Text1 { get; set; }
    [DataMember]
    public string Text2 { get; set; }
    [DataMember]
    public string DiscountText { get; set; }
    [DataMember]
    public string Price { get; set; }
}

I keep getting null values in all fields of the inner object. Although the rest of the fields in the DaObject are passed actual values. How can I fix this?

4

0 回答 0