wengMQ 发表于 2021-12-14 16:36:08

Core版本支持json post请求处理

源码地址:WebSamples15/JsViewerSamples/JSViewer_MVC_Core at main · activereports/WebSamples15 · GitHub

前端post请求


后端修改
1、nuget引入 Microsoft.AspNetCore.Mvc.NewtonsoftJson;core3.1版本推荐3.1.x版本
2、Startup.cs调整
public void ConfigureServices(IServiceCollection services)
      {
            services.AddControllers().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //json用非驼峰
            });

            services
                .AddLogging(config =>
                {
                  // Disable the default logging configuration
                  config.ClearProviders();

                  // Enable logging for debug mode only
                  if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
                  {
                        config.AddConsole();
                  }
                })
                .AddReporting()
                .AddMvc(options => options.EnableEndpointRouting = false);
      }

Bella.Yuan 发表于 2021-12-14 16:43:07

:hjyzw:
页: [1]
查看完整版本: Core版本支持json post请求处理