亲爱的,我正在将一个对象从angularjs发送到Web API。除2个数组外,所有属性均被发送到API并正确接收,它们在不知道原因的情况下在C#中为null接收,因此如果您能帮上忙 在部门(dep)数组中,我正在发送1个值$ scope.dep 在续数组中,我正在发送乘法值,可能是推送到数组不正确,我不知道 HTML
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="form-group">
<div class="col-xs-12">
<label class="control-label" for="name">Contracts <span class="danger">*</span></label>
</div>
<div class="col-xs-12">
<select id="example-post" class="form-control input-sm" multiple="multiple" ng-model="cont" ng-change="addcontracts(cont)">
<option ng-repeat="c in selectedcontracts" value="{{c.Sys_Key}}">{{c.Cont}}</option>
</select>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="form-group">
<div class="col-xs-12">
<label class="control-label" for="name">Department <span class="danger">*</span></label>
</div>
<div class="col-xs-12">
<select class="form-control input-sm" ng-model="dep" ng-options="d.Dep_key as d.dep for d in staffdepartments | unique:'dep'"></select>
</div>
</div>
</div>
Angular js
this.Repttx_PayRollTotal_Net = function (url, Attendlog) {
return $http.post(urlBase + '/' + url, Attendlog)
};
$scope.newcontracts = [];
$scope.addcontracts = function (cont) {
console.log(cont);
$scope.newcontracts = [];
$scope.newcontracts.push(cont) ;
console.log($scope.newcontracts);
}
var Attendlog = { DFrom: $scope.from1, Fg: $scope.fg, StaffKey: $scope.staffkey, StatusServ: $scope.jbsts, Cont: JSON.stringify($scope.newcontracts), Order: $scope.sor }
AtendanceReprtingSrv.Repttx_PayRollTotal_Net("AttendanceReprting/Repttx_PayRollTotal_Net", Attendlog).then(function (response) {
$scope.ttx = (response.data);
document.getElementById("frmrepodbc").src = $scope.ttx;
$("#dialog_PrintRptObc").modal("show");
})
C#类及其属性
public class Attendlogs
{
public DateTime DFrom { get; set; }
public short Fg { get; set; }
public long StaffKey { get; set; }
public int StatusServ { get; set; }
public int[] Dep { get; set; }
public int[] Cont { get; set; }
public int Order { get; set; }
}
C#
[HttpPost]
public string Repttx_PayRollTotal_Net([FromBody] Attendlogs logs)
{
DataTable DTres = new DataTable();
DTres = null;
HR_ReportingTimeAttendDL.ReportiingDL hr = new HR_ReportingTimeAttendDL.ReportiingDL();
DTres = hr.AttendLog(logs.DFrom, logs.Fg, logs.StaffKey, logs.StatusServ, logs.Dep, logs.Cont, logs.Order);
预先感谢
答案 0 :(得分:0)
您要将数组作为对象发送到api
续:JSON.stringify($ scope.newcontracts)
您可能需要循环处理数据并将id推送到数组中,然后将此数组发送到后端
因为在后端的Attendlogs类的模型上,您期望有一个整数数组。