raisul
raisul

Reputation: 640

How to manipulate JSON data?

I am using angular.js with asp.net mvc 4. I am trying to pass jason data through ajax request to an action of my controller. Here is my script:

$scope.items = [
   { Name: "Name1", Email: "Email1", Address: "Address1", ContactNo: "contactNo1"},
   { Name: "Name2", Email: "Email2", Address: "Address2", ContactNo: "contactNo1"}
];

var users = JSON.stringify($scope.items);
        $.ajax({
            type: "POST",
            url: "/Angular/saveData",
            data: users,
            dataType: "json",
            success: function (msg) {
                alert("Success");
            },
            error: function (msg) {
                alert("Error");
            }
        });

I can't figure out what will be my "saveData" action to manupulate the jason data?

Upvotes: 1

Views: 290

Answers (1)

Norbert Pisz
Norbert Pisz

Reputation: 3440

Controller:

 [HttpPost]
  public JsonResult saveData(DataClass[] items)
  {

  }

The data class:

public class DataClass {
    public string Name {get; set; }
    public string Email {get; set; }
    public string Address {get; set; }
    public string ContactNo {get; set; }
}

Upvotes: 2

Related Questions