How to turn off or handle camelCasing in JSON response ASP.NET Core?

后端 未结 7 1677
攒了一身酷
攒了一身酷 2020-11-29 07:55

I\'m running through a WintellectNOW course on ASP.NET Core/Web API/Angular 2. I have the API portion implemented, but for whatever reason, the JSON that is being returned h

相关标签:
7条回答
  • 2020-11-29 08:49

    For those who needs a solution about a PascalCase within Api Project that has not the Mvc services you should add this after AddControllers services

     // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllers().AddJsonOptions(jsonOptions =>
                    {
                        jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
                    })
                    .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); ;
            }
    
    0 讨论(0)
提交回复
热议问题