Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 无法使用angularjs将json数据发布到MVC控制器_Asp.net Mvc_Angularjs_Angularjs Scope - Fatal编程技术网

Asp.net mvc 无法使用angularjs将json数据发布到MVC控制器

Asp.net mvc 无法使用angularjs将json数据发布到MVC控制器,asp.net-mvc,angularjs,angularjs-scope,Asp.net Mvc,Angularjs,Angularjs Scope,我只是想将数据发布到我的数据中,它是JSON对象,但我不能。通过firebug发布的帖子显示,我实际上是在向服务器d发布json数据,但在调试控制器时,我的d为null $scope.update = function() { $http({ method: "POST", url: 'EditData', data: {d: $scope.myData}, }).success(func

我只是想将数据发布到我的数据中,它是JSON对象,但我不能。通过firebug发布的帖子显示,我实际上是在向服务器d发布json数据,但在调试控制器时,我的d为null

  $scope.update = function() {
        $http({
            method: "POST",
            url: 'EditData',
            data: {d: $scope.myData},
        }).success(function() {
            alert(data.msg);
        });
    };
我确实尝试过JSON.parse我的数据,但也没有成功

这是我的控制器:

public JsonResult EditData(string d)
我不确定我在这里做什么。可能有点傻(

试试:

$scope.update = function() {
    $http({
        method: "POST",
        url: 'EditData',
        data: $scope.myData,
    }).success(function() {
        alert(data.msg);
    });
};

这对我有效。JSON.stringify()


您的URL不应该是这样的:
Controller/Action
,例如:
/notes/edit
?删除数据对象后的逗号。
myData},
。还要检查您的网络请求头以确保传递了正确的数据,如果是,则可能是解决方案中的webconfig问题。@NewDev即将返回主页/EditDataouble检查过了。@ChristopherMarshall我能够将JSON.stringify成功了。我相信它仍然将我的JSON作为一个对象来对待。@ouble太棒了,很高兴你解决了这个问题!
 $scope.update = function() {
            $http({
                method: "POST",
                url: 'EditData',
                data: {d: JSON.stringify($scope.myData)},
            }).success(function() {
                alert(data.msg);
            });
        };