web-api POST body object always null

前端 未结 26 2896
余生分开走
余生分开走 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:19

    I was also trying to use the [FromBody], however, I was trying to populate a string variable because the input will be changing and I just need to pass it along to a backend service but this was always null

    Post([FromBody]string Input]) 
    

    So I changed the method signature to use a dynamic class and then convert that to string

    Post(dynamic DynamicClass)
    {
       string Input = JsonConvert.SerializeObject(DynamicClass);
    

    This works well.

提交回复
热议问题