Why does the ASP.Net MVC model binder bind an empty JSON array to null?

前端 未结 7 2087
误落风尘
误落风尘 2020-12-15 15:52

Here is my model class:

public class MyModel
{
    public Employees[] MyEmpls{get;set;}
    public int Id{get;set;}
    public OrgName{get;set;}
}

7条回答
  •  北海茫月
    2020-12-15 16:49

    The default behavior of C# array initialization is to null not empty array

    So if you send an empty array you will not initiate an empty array, but you will trigger the default initialization to null

    See the following link http://www.dotnetperls.com/null-array

提交回复
热议问题