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

前端 未结 7 2098
误落风尘
误落风尘 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:55

    If you are getting model.MyEmpls as null then you can create a condition on server side to stop raising exception like:

    if(model.MyEmpls !=null){
    ...
    }
    

    And you are getting it null because your MyEmpls is a Custom Class array and you are sending just [].

    Hope this helps you.

提交回复
热议问题