Angularjs和api之间的内部服务器错误500 [英] Internal server error 500 between Angularjs and api
本文介绍了Angularjs和api之间的内部服务器错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试保存从angularjs发送到api的数据,但出现错误500内部服务器错误.控制器是一个数组,它们来自html页面.任何帮助
I am trying to save data from angularjs sending it to an api but i have the error 500 internal server error. the controller is an array hols the scops coming from the html page. any help
控制器
$scope.save = function ()
{
$scope.setup.push({
"Spec_Code": $scope.spec, "Medical_CTG": $scope.deg, "Doctor_Code": $scope.st, "Main_Serv": $scope.stypecode, "Serv_Group": $scope.sgroupcode, "Sub_Serv": $scope.sub,
"Pat_Type": $scope.patype, "Calc_Type": $scope.calcs, "Calc_From": $scope.rfrom, "Calc_Val": $scope.calcvalue, "STAFF_TYPE": $scope.stafftype,
"pricelist": $scope.selectedpricelist
})
var promisePost = Doctorssetup.save($scope.setup);
promisePost.then(function (pl) {
}, function (err) {
console.log("Err" + err);
});
console.log($scope.setup);
}
var promisePost = Doctorssetup.save($scope.setup);
promisePost.then(function (pl) {
}, function (err) {
console.log("Err" + err);
});
console.log($scope.setup);
}
api
public HttpResponseMessage save ([FromBody]Doctorssetup setup)
{
obj.ExecNonQuery(string.Format("insert into Doctor_Cont_Det (Spec_Code,Medical_CTG,Doctor_Code,Main_Serv,Serv_Group,Sub_Serv, Pat_Type,Calc_Type,Calc_From,Calc_Val,Sys_Date,STAFF_TYPE,pricelist) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')"
, setup.Spec_Code
, setup.Medical_CTG
, setup.Doctor_Code
, setup.Main_Serv
, setup.Serv_Group
, setup.Sub_Serv
, setup.Pat_Type
, setup.Calc_Type
, setup.Calc_From
, setup.Calc_Val
, DateTime.Now
, setup.STAFF_TYPE
, setup.pricelist
));
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
return response;
}
非常感谢
推荐答案
您在控制器上的函数需要一个对象,但是您试图发布一个数组.进行如下更改,
Your function on the controller expects an object, but you are trying to post an array. Change it as follows,
$scope.setup = {
"Spec_Code": $scope.spec, "Medical_CTG": $scope.deg, "Doctor_Code": $scope.st, "Main_Serv": $scope.stypecode, "Serv_Group": $scope.sgroupcode, "Sub_Serv": $scope.sub,
"Pat_Type": $scope.patype, "Calc_Type": $scope.calcs, "Calc_From": $scope.rfrom, "Calc_Val": $scope.calcvalue, "STAFF_TYPE": $scope.stafftype,
"pricelist": $scope.selectedpricelist
});
在使用 JSON.stringify($ scope.setup);
also convert to string before posting it using JSON.stringify($scope.setup);
这篇关于Angularjs和api之间的内部服务器错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文