I am encountering an issue with my code where I have two classes and need to call two separate models using two store procedures to insert data into both tables. The controller is set up like this:
[HttpPost]
public IHttpActionResult AddData([FromBody]IList<Details> details, [FromBody] Request request)
{
var changeRequestResponse = db.sp_AddChangeRequests(request.EmpID, request.CreatedDate, request.Status).SingleOrDefault();
GenericResponse objResponse = null;
foreach (Details detail in details)
{
var data = JsonConvert.SerializeObject(db.sp_AddChangeRequestDetails(detail.CRID, detail.Category, detail.Info, detail.Col, detail.Reason).SingleOrDefault(), Formatting.Indented, settings);
objResponse = JsonConvert.DeserializeObject<GenericResponse>(data);
}
return Ok(objResponse);
}
My controller js file looks like this:
$scope.SubmitRequestForm = function(){
console.log($scope.changeReqCol);
var req = {
method: 'POST',
url: WebApiUrl + 'AddData',
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify($scope.changeReqCol)
}
console.log()
$http(req).then(function (data, status) {
console.log(data);
}, function (err, status) {
console.log(err);
});
};
When attempting to submit the data, I am experiencing the error mentioned above. Can someone please assist me in identifying what may be missing?