I have an object called DrawDie with the following properties:
ID
PlantID : int
QtyOnHand : int
SizeUS : double
SizeMetric : double
CaseSize : string
Style : string
I have an object called DieOrder with the following properties:
ID : int
DrawDie : DrawDie
DrawDieID : int
PlantID : int
PurchaseOrder : string
Qty : int
I would like to post my object to an MVC controller via an Ajax request. I would prefer not to use a 3rd party library. I am trying to post it like this:
var DieOrder = new Object();
var DrawDie = new Object();
DieOrder.Qty = $("#Qty").val();
DieOrder.DrawDieID = $("#DrawDieID").val();
DrawDie.CaseSize = $("#DrawDie_CaseSize").val();
DrawDie.Qty = $("#Qty").val();
DrawDie.ID = dieID;
DrawDie.QtyOnHand = 0;
DrawDie.SizeUS = $("#DrawDie_SizeUS");
DrawDie.SizeMetric = $("#DrawDie_SizeMetric");
DrawDie.PlantID = $("#PlantID").val();
DrawDie.IsTransfer = "N";
DieOrder.PlantID = $("#PlantID").val();
DieOrder.OrderedBy = $("#OrderedBy").val();
DieOrder.PurchaseOrder = $("#PurchaseOrder").val();
DieOrder.DrawDie = DrawDie;
$.ajax({
url: "Order/OrdDie",
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(DieOrder),
success: handleData
});
});
I have two questions. One, is my approach way off or is it okay ? I am getting an UncaughtType error: Converting circular structure to JSON. How do I restructure my request so I do not get such an error? I am unsure of why I am getting this error.
Thanks
Update:
DrawDie.SizeUS = $("#DrawDie_SizeUS").val();
DrawDie.SizeMetric = $("#DrawDie_SizeMetric").val();
I was missing the .val()