Search code examples
asp.net-mvcangularjsangularjs-scope

Can not post json data using angularjs to MVC controller


I simply want to post the data my data which is JSON object but I can not. the post via firebug shows that I am actually posting json data to server d, but when debugging the controller my d is null.

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

I did try to JSON.parse myData that didn't work either.

Here is my controller:

public JsonResult EditData(string d)

I am not sure what I am doing right here. probably something silly. :(


Solution

  • This worked for me. JSON.stringify();

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