私はangularjsとwebapiの初心者です。私はangularjsとwebapiの下に作成しました。私が直面している問題は、apiオブジェクトにnullとデータが含まれていないことです。誰でも私が間違っていることに気づくことができます。
角度コード:
$scope.GetReport = function() {
var ReportModel = {};
debugger;
var result = {};
if (angular.isDefined($scope.Report.FromDate))
ReportModel.FromDate = new Date($scope.Report.FromDate);
else
ReportModel.FromDate = null;
if (angular.isDefined($scope.Report.ToDate))
ReportModel.Todate = new Date($scope.Report.ToDate);
else
ReportModel.Todate = null;
ReportModel.UserID = '';
ReportModel.UserWWID = '1234';
ReportModel.UserRole = '';
ReportModel.ProjectType = '';
ReportModel.ProjStatus = 'In Progress';
ReportModel.CreatedBy = '11744439';
ReportModel.LGroup = '';
ReportModel.LUnit = '';
ReportModel.LTeam = '';
var config = {
headers: { 'Content-Type': 'application/json;charset=utf-8' },
datatype: JSON,
data: JSON.stringify(ReportModel)
};
result = $http.get('api/Project/GetReport', { params: ReportModel })
.then(function (response) {
result = response.data;
})
}, function (response) {
alert('Failed ' + JSON.stringify(response.statusText));
};
}
ウェブAPI:あなたが設定をコメントし、ちょうどペイロードとしてReportModel
を送ることができるように
public IHttpActionResult GetReport(ViewReportModel objViewRepotModel)
{
try
{
//Code here
}
catch (Exception ex)
{
return NotFound();
}
}
'$ http.post( 'api/Project/GetReport'、config)'のように 'configオブジェクト'と投稿を使わないのはなぜですか? – anoop
質問を書くときは、できるだけ小さなコードを使用して、同じ問題が発生します。問題に関連していない問題を取り除く。 – georgeawg