我将 json 对象传递给 asp.net mvc 控制器操作。两个参数都为空。
有人可以发现错误prolly错误的命名吗?
/* Source Unit */
var sourceParent = sourceNode.getParent();
var sourceUnitParentId = sourceParent == null ? null : sourceParent.data.key;
var sourceUnit = { unitId: sourceNode.data.key, parentId: sourceUnitParentId };
var sourceUnitJson = JSON.stringify(sourceUnit);
/* Target Unit */
var targetParent = targetNode.getParent();
var targetUnitParentId = targetParent == null ? null : targetParent.data.key;
var targetUnit = { unitId: targetNode.data.key, parentId: targetUnitParentId };
var targetUnitJson = JSON.stringify(targetUnit);
moveUnit(sourceUnitJson, targetUnitJson);
function moveUnit(sourceUnit, targetUnit) {
$.ajax({
url: '@Url.Action("Move", "Unit")',
type: 'POST',
data: { sourceUnit: sourceUnit, targetUnit: targetUnit },
success: function (response) {
},
error: function (e) {
}
});
}
[HttpPost]
public ActionResult Move(DragDropUnitViewModel sourceUnit, DragDropUnitViewModel targetUnit)
{
Unit sUnit = Mapper.Map<DragDropUnitViewModel, Unit>(sourceUnit);
Unit tUnit = Mapper.Map<DragDropUnitViewModel, Unit>(targetUnit);
_unitService.MoveUnit(sUnit, tUnit);
return new EmptyResult();
}