web-api POST body object always null

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

    In my case (.NET Core 3.0) I had to configure JSON serialization to resolve camelCase properties using AddNewtonsoftJson():

    services.AddMvc(options =>
    {
        // (Irrelevant for the answer)
    })
    .AddNewtonsoftJson(options =>
    {
        options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    });
    

    Do this in your Startup / Dependency Injection setup.

提交回复
热议问题