众所周知在.net core 里面这样使用很普遍 

但是为何在3.1当中是NULL呢?

public async Task<IActionResult> 方法名称([FromBody]CreateMapDto dto)
{ }

是这样微软的“天才”程序员在.net core 3.1 中Newtonsoft.Json 替换为了System.Text.Json 

在.NET Core 3之前,ASP.NET Core在内部使用了Newtonsoft.Json,现在它使用的是System.Text.Json。

 一个例子是一个数字字段,例如MyClass.Value1。如果从Javascript中传递“10”或10,Newtonsoft.Json将处理这个问题并将两者识别为10。默认情况下,对于System.Text.Json,该字段不能有引号,如果在Json中发布了引号,则会得到一个空的[FromBody]值。

解决方案 注入 AddNewtonsoftJson 引用Newtonsoft.Json

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages().AddNewtonsoftJson();

    //All your other code:
    //...
}

 

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-12-26
  • 2022-12-23
  • 2022-01-01
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-05-15
  • 2021-08-05
相关资源
相似解决方案