我在asp.net mvc 4中使用angular.js.我试图通过ajax请求将jason数据传递给我的控制器的动作。 这是我的剧本:
$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");
}
});
我无法弄清楚我的“saveData”操作会对jason数据进行操作吗?
答案 0 :(得分:2)
控制器:
[HttpPost]
public JsonResult saveData(DataClass[] items)
{
}
数据类:
public class DataClass {
public string Name {get; set; }
public string Email {get; set; }
public string Address {get; set; }
public string ContactNo {get; set; }
}