Sometimes, when AJAX posting to a controller, you may get a null model. Why?

Let’s exclude the obvious – you didn’t send a null payload. The most typical reason is, the serializer could not deserialize the payload into the target type, and it just silently sets it to null, but no exception is thrown. Take this example:

public class Data
{
    public string X { get; set; }
    public int Y { get; set; }
}

#pitfalls #aspdotnet core #aspdotnet

ASP.NET Core Pitfalls – Null Models in Post Requests
1.35 GEEK