Home > Software engineering >  Why does asp.net core deserialize json null property (list) as an empty list
Why does asp.net core deserialize json null property (list) as an empty list

Time:11-22

ASP.NET Core 5 deserializes json null property (list) as empty list in controller parameter (HttpPost).

I did not configure anything in startup.

The property is expected to be null instead of empty list.

CodePudding user response:

After experimenting, it turned out that the parameters in the controllers can be deserialized if the ajax request has an object in data without dataType, contentType. Sometimes it still doesn't work unfortunately, so in those cases I use JSON.stringify, along with contentType="application/json" and the [FromBody] attribute.

As serializer I use Newtonsoft.Json.

  • Related