本帖最后由 icy_fang 于 2017-7-21 14:36 编辑
感谢楼上的回答。
现在出现问题:data传递值为null,请帮忙看下,谢谢。
--------------------------------------------- html code ---------------------------------------------
function buildRequests(actions) {
var result = [];
var i;
var len;
var action;
var actionType;
var dataItem;
for (i = 0, len = actions.length; i < len; i++) {
action = actions;
actionType = action.type;
dataItem = action.dataItem;
if (actionType === 'update') {
// 这一段代码可以打印出正确的ID
console.log('id = ' + dataItem.ID);
result.push({
type: 'POST',
url: '/Home/TestUpdate',
data: { id: dataItem.ID }
});
} else if (actionType === 'delete') {
result.push({
type: 'DELETE',
url: '/api/records/' + dataItem.ID,
});
} else if (actionType === 'create') {
result.push({
type: 'POST',
url: '/api/records',
data: dataItem
});
}
}
// log 可以打印出来
// console.log('buildRequests = ' + result[0]);
return result;
}
--------------------------------------------- cs code ---------------------------------------------
/// <summary>
/// Update (string update_id, string NameCN, string NameEN, string ProvinceCN)
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public JsonResult TestUpdate(string id)
{
// id 是null, 此方法可用(已在页面初始化时测试过)
if (id != null)
{
// 更新数据
}
return Json(new object(), JsonRequestBehavior.AllowGet);
}
|