I'm going crazy. Maybe someone can help.
I have my ajax on the website passing data to the asmx on the backend.
the data is as so. and it's valid json. http://jsonlint.com/
{ "data": [{"Address":"addasdf","City":"casdf","County":"casdf","State":"dc","Zip":"33333","ReferenceID":"asdf","LegalDescription":"asdf","PreviousOwner":"asdf","ClientNotes":"sadf","AcquisitionType":"sadf","ClientAcquisitionDate":"asdf","ForeclosureDate":"asdf"}]}
The ajax sending the data is here. And as far as I can tell this is sending correctly and is right.
$.ajax({
type: "POST",
url: "/ServiceFolder/BulkOrder.asmx/insertBulk",
data: "{ \"data\": " + smyData + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, textStatus, jqXHR) { //
//alert(data);
console.log(data);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
console.log(xmlHttpRequest.responseText);
console.log(textStatus);
console.log(errorThrown);
alert("Screen shot this error getEntityMarkers: " + xmlHttpRequest.toString() + " " + textStatus.toString() + " " + errorThrown.toString());
}
});
I have my class that models the data being sent.
[Serializable]
public class BulkOrderObject
{
public List<BulkOrderObjectData> data { get; set; }
}
[Serializable]
public class BulkOrderObjectData
{
public string Address { get; set; }
public string City { get; set; }
public string County { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string ReferenceID { get; set; }
public string LegalDescription { get; set; }
public string PreviousOwner { get; set; }
public string ClientNotes { get; set; }
public string AcquisitionType { get; set; }
public string ClientAcquisitionDate { get; set; }
public string ForeclosureDate { get; set; }
}
And finally where I think my problems lie in the webmethod.
[WebMethod]
public string insertBulk(List<BulkOrderObject> data)
{
string myreturn = String.Empty;
myreturn += data.Count; // data returns count
//List<BulkOrderObject> l = data as List<BulkOrderObject>;
try
{
foreach (var i in data)
{
myreturn += i.data.Count; // error here.
}
}
catch (Exception ex)
{
myreturn += ex.ToString();
}
return myreturn;
}
something funky is going on here at public string insertBulk(List< BulkOrderObject > data) when I try to get the number of entries in data.count it shows that there's 1. however when I try to foreach the data in data it returns an error.
{"d":"1System.NullReferenceException: Object reference not set to an instance of an object.\r\n at
test.insertBulk(List`1 data)"}
It's as if it's not filling up the BulkOrderObjectData.
Any thoughts?