Reputation: 1177
I am working with the Draw2D library which allows for exporting of the JSON but when I try to do it I cannot get it to export to MVC. This is not an issue with Draw2D but rather lack of knowledge by me as to how to get it to work. I generate the JSON which looks like what is below
[
{
"type": "DBTable",
"id": "662b1fb8-5eb8-47a5-9f81-e48efb0d31bd",
"x": 80,
"y": 59,
"width": 99,
"height": 107,
"cssClass": "DBTable",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"name": "Default AutoAttendant",
"entities": [
{
"text": "0",
"id": "0c4c5414-1f35-4247-a4b7-38297aa0e5ff"
},
{
"text": "1",
"id": "706e1cb7-a9d1-461d-8230-0bf136c1d850"
}
]
},
{
"type": "NamedUser",
"name": "Scott",
"id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
},
{
"type": "NamedUser",
"name": "Nancy",
"id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
}
]
My Controller is very basic at the moment to weed out all potential side effect issues.,
public ActionResult Draw2dRetrieveJSON(AllJson AllJsontxt)
{
My Class looks like this
public class AllJson
{
public IEnumerable<HostedVoiceUserJson> HostedVoiceUserJson { get; set; }
//public IEnumerable<HostedVoiceHuntGroupJson> HostedVoiceHuntGroupJson { get; set; }
//public IEnumerable<HostedVoiceAAJson> HostedVoiceAAJson { get; set; }
//public IEnumerable<HostedVoiceConnectionJSON> HostedVoiceConnectionJSON { get; set; }
}
I followed this post which got me as far as getting the "NamedUser" objects to post by themselves and with me manually changing the JSON string to match
{
"HostedVoiceUserJson": [
{
"type": "NamedUser",
"name": "Scott",
"id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
},
{
"type": "NamedUser",
"name": "Nancy",
"id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
}
]
}
Of course I cannot sit here and manually change these all the time I need to be able to find away to get this to work so that I can post multiple different types back all together.
Upvotes: 0
Views: 219
Reputation: 41
It looks like your JSON is an array of objects. You need homogeneus JSON collections in order to be recognized automatically by the ModelBinder.
Based on the type, you could separate your JSON objects and send them in different, homogeneous arrays. This way you could match your model class in C#
Upvotes: 0