web-api POST body object always null

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

    Check if JsonProperty attribute is set on the fields that come as null - it could be that they are mapped to different json property-names.

    0 讨论(0)
  • 2020-11-27 15:39

    I had this problem in my .NET Framework Web API, because my model existed in a .NET Standard project that referenced a different version of data annotations.

    Adding the ReadAsAsync line below highlighted the cause for me:

    public async Task<HttpResponseMessage> Register(RegistrationDetails registrationDetails)
    {
        var regDetails = await Request.Content.ReadAsAsync<RegistrationDetails>();
    
    0 讨论(0)
提交回复
热议问题