1

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. :(

10
  • Shouldn't your URL be something like: Controller/Action, ex: /notes/edit? Commented Dec 4, 2014 at 16:21
  • Remove the comma after your data Object. myData},. Also check your network request headers to make sure the correct data is being passed, if it is, it's probably a webconfig issue in your solution. Commented Dec 4, 2014 at 16:21
  • @NewDev that is going to Home/EditData double checked it. Commented Dec 4, 2014 at 16:22
  • 1
    @ChristopherMarshall I was able to JSON.stringify and it worked. I believe it was still treating my json as an object. Commented Dec 4, 2014 at 16:38
  • 1
    @NoviceDeveloper Awesome, glad you got it worked out! Commented Dec 4, 2014 at 16:38

2 Answers 2

1

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);
            });
        };
Sign up to request clarification or add additional context in comments.

Comments

0

try:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.