ASP.NET Core API POST parameter is always null

前端 未结 9 504
自闭症患者
自闭症患者 2020-12-14 00:27

I have read the following:

  • Asp.net Core Post parameter is always null
  • asp.net webapi 2 post parameter is always null
  • web-api POST body object
9条回答
  •  囚心锁ツ
    2020-12-14 01:12

    In my case, I had it setup like @guhyeon suggested, with a model class containing only a string property. Except, it wasn't defined as a property, it was simply

    public class PdfInfoRequestDto
    {
        public string PdfInBase64;
    }
    

    And for some reason, this worked for a .net framework 4.7.2 webapi and I could receive the value I needed from the request body. But when I tried replicating the same in a .net core 3.1 webapi, with the same request, models and everything, the value in PdfInBase64 always arrived in my controller as null. After changing the field to a property:

    public string PdfInBase64 { get; set; }
    

    I started correctly getting the value that was being passed in the request body.

提交回复
热议问题