Angularjs 和 api 之间的内部服务器错误 500 [英] Internal server error 500 between Angularjs and api

查看:24
本文介绍了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);
}

接口

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆