Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:52:54+00:00 2026-06-01T19:52:54+00:00

JSON.NET deserializes it fine, but whatever mvc uses for controller parameter binding barfs hard.

  • 0

JSON.NET deserializes it fine, but whatever mvc uses for controller parameter binding barfs hard. Can I do anything else to make this work?

The bits:

  public partial class Question
  {
    public Dictionary<string, List<QuestionExtendedProp>> TemporaryExtendedProperties { get; set; }
  }

And the controller method

[HttpPost]
public JsonResult SaveQuestions(Question[] questions)
{
  var z =
    JsonConvert.DeserializeObject(
      "{'Options':[{'PropKey':'asdfasd','PropVal':'asdfalkj'},{'PropKey':'fdsafdsafasdfas','PropVal':'fdsafdas'}]}",
      typeof (Dictionary<string, List<QuestionExtendedProp>>)) as Dictionary<string, List<QuestionExtendedProp>>;
  //this deserializes perfectly. z is exactly what I want it to be
  //BUT, questions is all wrong. See pic below

  //lots of code snipped for clarity, I only care about the incoming questions object
  return Utility.Save(questions);
}

Here’s what MVC gives me for this exact string (Pulled from fiddler, extras snipped for your reading pleasure)

    "TemporaryExtendedProperties":{"Options": 
        [{"PropKey":"NE","PropVal":"NEBRASKA"}, 
         {"PropKey":"CORN","PropVal":"CHILDREN OF"}, 
         {"PropKey":"COW","PropVal":"MOO"}]}

Weird deserialized values in Locals panel

Why does MVC mangle the binding from this perfectly fine json string and how can I get it to not do so? I have complete control over the json structure and creation.

Edit
I tried changing the type of Question.TemporaryExtendedProperties to List<KeyValuePair<string, List<QuestionExtendedProp>>>, but that didn’t work either. Here’s the new json (which matches exactly what System.Web.Script.Serialization.JavaScriptSerializer serializes an object to!)

{
   TemporaryExtendedProperties: [
      {
         Key: 'Options',
         Value: [
            {
               PropKey: 'NEBRASKA',
               PropVal: 'NE'
            },
            {
               PropKey: 'DOG',
               PropVal: 'CORN'
            },
            {
               PropKey: 'MEOW???',
               PropVal: 'COW'
            }
         ]
      }
   ]
}

That didn’t work either. It’s deserialized by the controller to a List<blah,blah> properly, with a count of 1 (as expected), but the Key and Value are both null. Json.NET again handles it perfectly.

Ugh.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:52:55+00:00Added an answer on June 1, 2026 at 7:52 pm

    I ended up just removing the need for a dictionary. The new code looks like this:

    //Other half is autogenerated by EF in models folder
    public partial class Question
    {
        public List<QuestionExtendedProp> TemporaryExtendedProperties { get; set; }
    }
    
    //Other half is autogenerated by EF in models folder
    public partial class QuestionExtendedProp
    {
        public string DictionaryKeyValue { get; set; }
    }
    

    mvc handles this just fine. My controller now looks like this

    [HttpPost]
    public JsonResult SaveQuestions(Question[] questions)
    {
    
      foreach (var q in questions)
      {
        //do regular question processing stuff
        //20 lines later
        IEnumerable<IGrouping<string, QuestionExtendedProp>> ExtendedPropGroups = q.TemporaryExtendedProperties.GroupBy(x => x.DictionaryKeyValue);
        foreach (IGrouping<string, QuestionExtendedProp> group in ExtendedPropGroups)
        {
          string groupKey = group.Key;
          foreach (var qexp in group)
          {
            //do things here
          }
        }
      }
      //rest of the stuff now that I've processed my extended properties...properly
      return Utility.SaveQuestions(questions);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

json.net (newtonsoft) I am looking through the documentation but I can't find anything on
I know this is not hard, but I've been staring at the JSON.Net documentation
How does MVC asp.net serialization work for Json object on Controller actions ? For
Does .NET 4 come with any class that serializes/deserializes JSON data? I know there
i'm trying to deserialize a json string pulled from the web using json.net, but
I am using jQuery.ajax(...) to retrieve JSON data from an ASP.NET MVC service. When
I'm new with JSON.NET and I'm trying to deserialize a JSON string to a
I started to use Json.NET to convert a string in JSON format to object
I am using json.net to parse objects and delivering them to a webservice I
I am using Json.NET to serialize an object graph. For each object that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.