I am passing two JSON objects to an ASP.NET MVC controller action, but both parameters are showing as null.
Can anyone identify the error, possibly related to incorrect naming?
/* 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();
}