Receiving AJAX jQuery array in c#
I have a JSON array like this:
"{structChangeList : '[{"structChange":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}]'"
or
"[{"structChangeList":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}]"
and various other variationd which I am trying to pick up with a web method like
[WebMethod]
public string receiveStructureUpdates3(List<StrutureData> structChangeList)
{
return "Hello World";
}
where StructureData is:
[DataContract]
public class StrutureData
{
[DataMember]
public string id { get; set; }
[DataMember]
public string parentId { get; set; }
[DataMember]
public string date { get; set; }
}
It works fine when I try to pick up a non array like:
"{"structChange":{"id":"Level1.Secon开发者_如何学JAVAd","parentId":"Level1.First","date":"2011-01-01"}}"
with:
[WebMethod]
public string receiveStructureUpdates2(StrutureData structChange)
{
}
But I can't get the array working. Any ideas?
EDIT:
To use an array/list, change:
"{"structChange":{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}}"
To
{"structChange": [{"id":"Level1.Second","parentId":"Level1.First","date":"2011-01-01"}]}
Because .Net is looking for structChage
, it wants to find that first. Since structChange
is a List
the value for that key needs to be an array.
This is the correct way to send data to an action in the controller
data: "{someField : [[\"Level1.Second\",\"Level1.First\",\"2011-01-01\"]] }
精彩评论