I have this piece of code which works perfectly fine if I set a break point at code behind and let the value become zero and continue to run the rest of the code.
However it will break if i did not set a break point and let it run and the value will become 2 and break.
Does anyone have any idea why? The AJAX code below triggers when the user enters something in the textbox.
function getmachineinfo(serial) {
$.ajax({
url: '@Url.Action("actionname", "controller")',
type: "POST",
data: { "serial": serial },
success: function (data) {alert('success')}, error: function (err) {
alert(err)
}}
public JsonResult getmachine(string serial)
{
var machine= service.GetWarrantyDetailsBySerial(serial);
result.AccessoriesWs = new List<AccessoriesW>();
//set break point here and let the result.AccessoriesW to be re declared and set to 0 and it will works.if i don set break point.result.AccessoriesW will not have enough time to reset to zero.
return Json(machine, JsonRequestBehavior.AllowGet);
}
Javascript error
A circular reference was detected while serializing an object of type
Result is parent object and AccessoriesW is child object resetting the child object will not get any errors.
Update solution
instead of using
result.AccessoriesWs = new List<AccessoriesW>();
i change it to below and problem solved. i think re declaring constructor is too slow for ajax.
result.JuraAccessoriesWs.Clear();