0

Is it possible to pass in JSON array of array to my List of Lists model property and it bind properly? Or must I make my .NET model an array of array too? My Clients pass me JSON to my model in the controller and the list> property of the model is always empty.

Here is how my model looks.

[DataContract]
public class EntityModel
{
    [DataMember]
    public string Username { get; set; }
    [DataMember]
    public List<List<SocialMediaModel>> socialMedias { get; set; }
}

Here is how the "SocialMediaModel" looks

[DataContract]
public class SocialMediaModel
{
    [DataMember]
    public string Name { get; set;}
    [DataMember]
    public string URL { get; set; }
    [DataMember]
    public string Handle { get; set; }
    [DataMember]
    public bool Can_Solicit { get; set; }
}

And then here is the controller's method signature

public PostResponse Post(string token, EntityModel entity)
{
    //Implementation here
}

If this is possible, how might the JSON look? I'm trying to help my clients with their JSON formatted requests. Thanks!

2
  • 1
    ASP.NET MVC model binding can map JSON arrays to generic lists. Are you trying to find out what the JSON will look like? Commented Oct 22, 2014 at 15:11
  • 1
    Yes, first I wanted a straight forward "yes" or "no" if JSON arrays bind to generic lists. If "yes" I was hoping I could get an example of how the JSON might look. Thanks! Commented Oct 22, 2014 at 15:14

1 Answer 1

1

ASP.NET MVC model binding can map JSON arrays to generic lists. Here's how an example JSON would look:

{
   "Username":"Username3c800c78-bf8a-4da2-8ab4-cb828df19ec0",
   "socialMedias":[
      [
         {
            "Name":"Name1d4c5229-1ca1-496d-8433-5bbfcb22641e",
            "URL":"URL1150cbf7-6fae-41a9-b899-e4679a02364d",
            "Handle":"Handled486c626-1480-4339-bbba-77c965e9a79f",
            "Can_Solicit":true
         },
         {
            "Name":"Name8af140ce-6ad1-46e1-8d6b-9dca5aa6e622",
            "URL":"URLc2bf8d29-423f-4df4-a958-200405a92558",
            "Handle":"Handle6d8ef6a9-15f7-42be-be70-54d7a9b7ae47",
            "Can_Solicit":false
         },
         {
            "Name":"Nameb1869836-63fe-4bd0-a70d-498289f0cded",
            "URL":"URLeb29ce8e-eff3-42e9-bc8d-86da0c8107b1",
            "Handle":"Handle9fe10130-35cb-4eda-a46f-881b73cac24f",
            "Can_Solicit":true
         }
      ],
      [
         {
            "Name":"Name435c040b-a235-41cd-ae8c-b12169ce1dfd",
            "URL":"URLdf9654bf-527b-42fc-9f99-2c0d031f8f6f",
            "Handle":"Handle5ee19ab0-6093-4497-9636-a11f751bd15c",
            "Can_Solicit":false
         },
         {
            "Name":"Name582ea19a-911f-49ae-8e48-2a3429155959",
            "URL":"URL7d99662e-463d-4b8e-9a4d-56bfadce374f",
            "Handle":"Handle530069e0-b1c6-4d9a-b99d-da245b36b2e8",
            "Can_Solicit":true
         },
         {
            "Name":"Name2ff4edd8-03ce-41cc-87ec-e18194ada6ed",
            "URL":"URL41614488-f52a-4f37-a0dd-bc34f1207b19",
            "Handle":"Handle17fb8b9b-0365-4cce-805e-90752358a863",
            "Can_Solicit":false
         }
      ],
      [
         {
            "Name":"Namebd1938d5-17f9-4cb7-b859-a20ab7affc77",
            "URL":"URLa66d2033-c373-497a-a211-7668bd5ad014",
            "Handle":"Handle2842ff4e-2afd-4813-b706-2c48eb9a2d06",
            "Can_Solicit":true
         },
         {
            "Name":"Namecc874248-c5ec-4a04-92d5-48121d24d833",
            "URL":"URL73040afb-8b73-48ea-9c8e-9b1be7f31fe0",
            "Handle":"Handle98d10e5b-affb-4a13-b2b7-4001165b42d5",
            "Can_Solicit":false
         },
         {
            "Name":"Name4f24b8dc-ede7-48d8-9001-7cefeaf4fc16",
            "URL":"URLfa94bb52-8d66-4e1a-9373-8b909808ecf3",
            "Handle":"Handle03e43ade-8f49-47d8-bcdd-70e8b3c01740",
            "Can_Solicit":true
         }
      ]
   ]
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.