2017-06-14 1 views
0

ich ein Modell mit einer Liste haben innen:

[Serializable] 
    public class DrivingLicenceCommon 
    { 
     [XmlAttribute("IdDrivingLicence")] 
     public int IdDrivingLicence { get; set; } 

     [XmlAttribute("IdUser")] 
     public string IdUser { get; set; } 

     [XmlAttribute("Lastname")] 
     public string Lastname { get; set; } 

     [XmlAttribute("Firstname")] 
     public string Firstname { get; set; } 

     [XmlAttribute("BirthData")] 
     public string BirthData { get; set; } 

     [XmlAttribute("BirthPlace")] 
     public string BirthPlace { get; set; } 

     [XmlAttribute("IssueDate")] 
     public string IssueDate { get; set; } 

     [XmlAttribute("ExpirationDate")] 
     public string ExpirationDate { get; set; } 

     [XmlAttribute("ReleasedBy")] 
     public string ReleasedBy { get; set; } 

     [XmlAttribute("Number")] 
     public string Number { get; set; } 

     [XmlAttribute("IdCertification")] 
     public int IdCertification { get; set; } 

     [XmlAttribute("IsVerified")] 
     public bool IsVerified { get; set; } 

     [XmlAttribute("CreationDate")] 
     public DateTime CreationDate { get; set; } 

     [XmlAttribute("CertificationDescription")] 
     public string CertificationDescription { get; set; } 

     [XmlAttribute("DrivingLicenceCategoryModel")] 
     public List<DrivingLicenceCategoryModel> DrivingLicenceCategoryModel { get; set; } 

     public DrivingLicenceCommon() 
     { 
      this.IdDrivingLicence = 0; 
      this.IdUser = string.Empty; 
      this.Lastname = string.Empty; 
      this.Firstname = string.Empty; 
      this.BirthData = string.Empty; 
      this.BirthPlace = string.Empty; 
      this.IssueDate = string.Empty; 
      this.ExpirationDate = string.Empty; 
      this.ReleasedBy = string.Empty; 
      this.Number = string.Empty; 
      this.IdCertification = 0; 
      this.IsVerified = false; 
      this.CreationDate = DateTime.Parse("01/01/1900"); 
      this.DrivingLicenceCategoryModel = new List<DrivingLicenceCategoryModel>(); 
     } 

Wenn ich mein Eckige Objekt zu MVC-Controller POST mein DrivingLicenceCommon ist voll, aber die Liste innen leer.

Ich benutze diesen Aufruf zur Aktion

$http({ 
    method: 'POST', 
    url: '/Dashboards/DrivingLicence_Add', 
    params: $scope.drivingLicenceCard, 
    headers: 
    { 
     "RequestVerificationToken": getToken(), 
    }, 
}).then(function (result) { 
}, function (response) { 
    // error handler 
}); 

Die JSON für $ scope.drivingLicenceCard:

{ "DrivingLicenceCategoryModel": [ { "category": 1, "categoryDescription": "AM", "startDate": "2017-05-31T22:00:00.000Z", "endDate": "2017-05-31T22:00:00.000Z", "code": "1" }, { "startDate": "2017-05-31T22:00:00.000Z", "endDate": "2017-05-31T22:00:00.000Z", "category": 2, "categoryDescription": "A1", "code": "12" } ], "lastname": "1", "firstname": "2", "birthData": "3", "birthPlace": "4", "issueDate": "5", "expirationDate": "6", "releasedBy": "7", "number": "8" } 

und der Controller-Methode, ist dies:

[HttpPost] 
[ValidateAntiForgeryToken] 
public JsonResult DrivingLicence_Add(DrivingLicenceCommon drivingLicenceCommon) 

Antwort

0

ersetzen params Datenschlüsselwort in Ihrem Konfigurationsblock

+0

Nein! Mit "Daten" ist komplett leer. Bei "Params" ist nur die Liste leer. Für den aktuellen Workaround verwenden Sie $ .ajax (Post) mit FromBody im Controller! –

Verwandte Themen