-1
我有一個客戶端使用typecript創建的類的列表,現在我想將它發送到webmethod。 我的打字稿代碼如下:如何將客戶端的類列表發送到帶有AJAX的webmethod
class MakeReportData {
LocalName: string;
FldSi: number;
ViewSi:number;
TypeName:string ;
CheckBoxshow :boolean ;
CheckBoxFilter:boolean;
}
我的Ajax代碼如下:
var temp: MakeReportData[] = [];
for (var i = 0; i < $scope.myData.ReportDetail.length; i++) {
var rep: MakeReportData=new MakeReportData();
rep.LocalName = $scope.myData.ReportDetail[i].LocalName;
rep.FldSi = $scope.myData.ReportDetail[i].FldSi;
rep.ViewSi = $scope.myData.ReportDetail[i].ViewSi;
rep.TypeName = $scope.myData.ReportDetail[i].TypeName;
rep.CheckBoxshow = $scope.myData.ReportDetail[i].CheckBoxshow;
rep.CheckBoxFilter = $scope.myData.ReportDetail[i].CheckBoxFilter;
temp.push(rep);
}
var tedata = JSON.stringify({ itm: temp });
alert(tedata);
$.ajax({
type: "POST",
url: "MakeReport.aspx/GetList",
contentType: "application/json; charset=utf-8",
data: tedata ,
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (data, status, jqXHR) {
alert(status);
alert(jqXHR);
}
});
我的webmethod低於:
[WebMethod]
public static string GetList(MakeReportData[] itm)
{
return "";
}
我在C#類是這樣的:
public class MakeReportData
{
public string LocalName { get; set; }
public int FldSi { get; set; }
public int ViewSi { get; set; }
public string TypeName { get; set; }
public bool CheckBoxshow { get; set; }
public bool CheckBoxFilter { get; set; }
}
我想將MakeReportData的列表發送到服務器webmethod。 我的問題是webmethod不會調用。