Web API complex parameter properties are all null

前端 未结 18 1544
长情又很酷
长情又很酷 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条回答
  •  难免孤独
    2020-11-30 05:14

    I guess problem is that your controller is expecting content type of [FromBody],try changing your controller to

    public HttpResponseMessage Post(PreferenceRequest request)
    

    and ajax to

    $.ajax({
        type: "POST",
        data: JSON.stringify(request);,
        dataType: 'json',
        contentType: "application/json",
        url: "http://localhost:1111/service/User",
    

    By the way creating model in javascript may not be best practice.

提交回复
热议问题