I have a GET method in angularjs that receives data from an API controller in C#. The controller is returning the data and the $http get method is receiving a response, but the response content body is empty.
My HttpGet API controller function:
[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}");
}
}
The object I want to return:
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; }
}
The GET method:
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!";
})
}
My confirmData variable in my controller contains data when the function returns. My angularjs GET method returns success with data.length equal to 1, but there are no values contained in data.
Can anyone shed some light on why my data is not being transferred properly?