Warum hat die ASP.Net MVC-model-binder binden ein leeres JSON-array auf null?

Hier ist meine model-Klasse:

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

Vorbei an der unterhalb der JSON-Struktur-Objekt mit MyEmpls as empty array zu MVC-controller.

["Id":12, "MyEmpls":[], "OrgName":"Kekran Mcran"]

Controller

[HttpPost]
public ActionResult SaveOrg(MyModel model)
{
  //model.MyEmpls is null here
}

Ich erwarte mode.MyEmpls eine leere c# - array nicht null ist. Ist ein custom-Modell binder notwendig, um ein leeres array?

  • Und MyEmpls ist nicht null, wenn Sie einen Mitarbeiter über JSON?
  • Warum nicht u prüfen Sie in Ihrem action-Methode, wenn myEmpls null ist, dann definieren Sie diese als eine leere c# - array?
InformationsquelleAutor Billa | 2014-04-16
Schreibe einen Kommentar