在前端发送Ajax请求,需要制定contentType为“application/json”,并且将数据源以JSON.stringify方式序列化。
var itemList=[{'id':1,'name':'apple'},{'id':2,'name':'orange'},{'id':3,'name':'banana'}];
$.ajax({
url:'/controller/actionMethod',
contentType:'application/json',
data: JSON.stringify(itemList),
type:'POST',
success:function(response){ //Success Callback },
error: function (xhr, ajaxOptions, thrownError) { //Error Callback }
});
在控制器中使用List
[HttpPost]
public JsonResult actionMethod(List- itemList)
{
// Some code here
}