Web API complex parameter properties are all null

前端 未结 18 1510
长情又很酷
长情又很酷 2020-11-30 04:18

I have a Web API service call that updates a user\'s preferences. Unfortunately when I call this POST method from a jQuery ajax call, the request parameter object\'s proper

18条回答
  •  萌比男神i
    2020-11-30 05:15

    I face this problem this fix it to me

    1. use attribute [JsonProperty("property name as in json request")] in your model by nuget package newton
    2. if you serializeobject call PostAsync only

    like that

    var json = JsonConvert.SerializeObject(yourobject);
    var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
    var response = await client.PostAsync ("apiURL", stringContent);
    
    1. if not work remove [from body] from your api

提交回复
热议问题