我有一个带有List的模型:
[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>();
}
当我将Angular对象发布到MVC控制器时,我的DrivingLicenceCommon已满,但List里面是空的。
我使用此Call for the Action
$http({
method: 'POST',
url: '/Dashboards/DrivingLicence_Add',
params: $scope.drivingLicenceCard,
headers:
{
"RequestVerificationToken": getToken(),
},
}).then(function (result) {
}, function (response) {
// error handler
});
$ scope.drivingLicenceCard的JSON:
{ "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" }
控制器方法是这样的:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult DrivingLicence_Add(DrivingLicenceCommon drivingLicenceCommon)
答案 0 :(得分:0)
将params替换为配置块中的data关键字