web-api POST body object always null

前端 未结 26 2914
余生分开走
余生分开走 2020-11-27 15:03

I\'m still learning web API, so pardon me if my question sounds stupid.

I have this in my StudentController:

public HttpResponseMessage          


        
26条回答
  •  失恋的感觉
    2020-11-27 15:14

    If the any of values of the request's JSON object are not the same type as expected by the service then the [FromBody] argument will be null.

    For example, if the age property in the json had a float value:

    "age":18.0

    but the API service expects it to be an int

    "age":18

    then student will be null. (No error messages will be sent in the response unless no null reference check).

提交回复
热议问题