title: How to pass Javascript dictionary to controller where C# dictionary value is an object
body: <p>Imagine this Javascript dictionary:</p>
  
  <pre><code>var things = {};
  things['1'] = 10;
  things['2'] = 11;
  </code></pre>
  
  <p>Here's a little bit of ajax code:</p>
  
  <pre><code>$.ajax({
      url: '/Controller/Foo',
      type: 'POST',
      data: {
          things: things
      },
  </code></pre>
  
  <p>Here's something that works:</p>
  
  <pre><code>[HttpPost]
  public IActionResult Foo(Dictionary&lt;string, int&gt; things)
  </code></pre>
  
  <p>things will show that 1 maps to 10 and 2 maps to 11.</p>
  
  <p>Here's something that DOES NOT work:</p>
  
  <pre><code>[HttpPost]
  public IActionResult Foo(Dictionary&lt;string, object&gt; things)
  </code></pre>
  
  <p>things will show that 1 maps to null and 2 maps to null.</p>
  
  <p>I can not change the Dictionary types.  In reality, that Dictionary is part of a complex object that is used throughout the application (on the C# side of things).  What you are looking at is a dumbed-down example.</p>
  
  <p>In addition, JSON.stringify does not help at all.  In fact, if I stringify the dictionary I get a count of 0, with no values.</p>
  
  <p>Using C# to express my point, I think the expectation is more this (than what is currently happening):</p>
  
  <pre><code>int x = 5;
  object foo = (object)x;
  </code></pre>
  
  <p>The dictionary was defined like this because one could be doing:</p>
  
  <pre><code>things[key] = 1;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>things[key] = "string";
  </code></pre>
  
  <p>that's why it was declared as an object.</p>
  
  <p>I am using ASP.NET Core if that matters (and jquery 3.4.1).</p>
  
  <p>Thank you.</p>