我想使用ajax从我的视图向控制器发送数组 所以我在我的视图中使用以下代码jquery
$("#mainBody").on("click", "#newAdd", function () {
var myobjects = new Array();
myobjects[0]={ "Name": "Ali", "job": "Developer" };
myobjects[1] = { "Name": "Mohamed", "job": "Tester" };
myobjects[2] = { "Name": "AHmed", "job": "Manager" };
var parameters = { "myobjects": myobjects };
$.ajax({
type: "POST",
url: '@Url.Action("NewAdd")',
dataType: 'json',
data: parameters,
async: false,
success: function () {
alert("Hi");
}
});
});
和我的控制器一样:
[HttpPost]
public JsonResult NewAdd(employee[] myobjects)
{
return Json(new { success = true,data="ok" });
}
我的员工模型:
public class employee { public string Name { get; set; } public string job { get; set; } }
问题是当我调试时发现我的控制器actiobn将myobjects计为三个但每个内容都为空