Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
MVC JSON Method not binding Dictionary properly

We are attempting to post data from JavaScript corresponds to a Dictionary<string, List> in C#

public class SubmittedObject {
    public string T;
    public SomeViewModel ViewModel;
}

public class SomeViewModel {
    public int Id;
    public Dictionary<string, List<ItemViewModel>> Items;
    public object Other;
}

public class ItemViewModel { 
    public int id; 
    public string value; 
} //shown as member variables for simplicity

JSON looks like:

{
    "t": "a",
    "viewModel": {
        "id": 0,
        "items": {
            "firstItem": [
                {
                    "id": 1,
                    "value": "1"
                }
            ],
            "secondItem": [
                {
                    "id": 2,
                    "value": "2"
                }
            ]
        },
        "other": null
    }
}

When the JS object gets submitted to

[HttpPost]
public ActionResult Save(string t, SubmittedObject viewModel)
{...}

saveViewModel gets interpreted with the first item in the Dictionary as key="FirstItem[0]" and value of null. SecondValue gets interpreted in like manner with key="SecondItem[0]" and value of null.

The current work-around is to serialize the submission data and submit it as a string; NewtonSoft parses it as expected.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!