我有一個angularjs中的GET方法,它從C#中的API控制器接收數據。控制器正在返回數據,$ http get方法正在接收響應,但響應內容正文爲空。
我HTTPGET API控制器功能:
[HttpGet]
[Route("api/LandingPage/GetByDate")]
public HttpResponseMessage GetByDate(DateTime startDate, DateTime endDate)
{
try
{
var startDateParam = new SqlParameter("@startDate", startDate);
var endDateParam = new SqlParameter("@endDate", endDate);
var confirmData = m_databaseObject.Database.SqlQuery<PageModel>("[dbo].[GetPageData] @startDate,@endDate", startDateParam, endDateParam).ToList();
return Request.CreateResponse(HttpStatusCode.OK, confirmData);
}
catch (Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Error occured {e.Message} {startDate:yyyy-MM-dd} {endDate:yyyy-MM-dd}");
}
}
我想返回的對象:
public class PageModel
{
string Name { get; set; }
int? FirstTotal { get; set; }
int? FisrtInitial { get; set; }
int? FisrtApproval { get; set; }
int? SecondTotal { get; set; }
int? SecondInitial { get; set; }
int? SecondApproval { get; set; }
int? Validated { get; set; }
int? NotSettled { get; set; }
}
GET方法:
this.getLandingPage = function ($scope) {
$scope.error = "";
$scope.message = "";
return $http({
method: "GET",
url: apiName + "LandingPage/GetByDate?startDate=" + $scope.StartDate + "&endDate=" + $scope.EndDate,
headers: { 'Content-Type': 'application/json' }
}).success(function (data) {
if (data.length === 0)
$scope.message = "No Data found";
else {
$scope.LandingPageData = data;
}
}).error(function (error) {
$scope.LandingPageData = null;
if (error)
$scope.error = error.Message;
else
$scope.error = "Data services may not be running, Please check!";
})
}
我在我的控制器confirmData
變量包含數據函數返回時。我的angularjs GET方法返回成功,data.length
等於1,但data
中沒有包含任何值。
任何人都可以闡明爲什麼我的數據沒有被正確傳輸嗎?
裏面有什麼數據?你嘗試過'data.data'嗎? –
'data'包含大小爲1的對象數組和空對象 –
您是否調試過您的控制器並確保confirmData實際上具有值? –