title: ASP.NET MVC3 submit post passing a Dictionary to Controller
body: <p>I have a dictionary being used. And when the "submit" is hit, how do I also pass the dictionary with the values in it to the [HttpPost] controller method? <br>
  Currently in the [HttpPost] method, the DummyDictionary is empty, how would I fix this?</p>
  
  <p><br>Thanks!</p>
  
  <h2>MODEL</h2>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using DummyMVC.Objects;
  
      namespace DummyMVC.Models
      {
          public class TheModel
          {
              public TheObject Obj { get; set; }
              public Dictionary&lt;string, TheObject&gt; DummyDictionary { get; set; }
          }
      }
  </code></pre>
  
  <h2>CONTROLLER</h2>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using DummyMVC.Models;
      using DummyMVC.Objects;
  
      namespace DummyMVC.Controllers
      {
          public class DummyController : Controller
          {
              //
              // GET: /Dummy/
              [HttpGet]
              public ActionResult Index()
              {
                  TheModel m = new TheModel();
                  m.Obj = new Objects.TheObject();
                  TheObject a_obj = new TheObject();
                  a_obj.Name = "Joe";
                  m.DummyDictionary = new Dictionary&lt;string, Objects.TheObject&gt;();
                  m.DummyDictionary.Add("VT", a_obj);
                  return View(m);
              }
  
              [HttpPost]
              public ActionResult Index(TheModel model)
              {
                  // HERE THE DICTIONARY is EMPTY, where all the form values should exist.
                  string test = "";
                  return View(model);
              }
  
          }
      }
  </code></pre>
  
  <h2>VIEW</h2>
  
  <pre><code>    @model DummyMVC.Models.TheModel
  
      @{
          ViewBag.Title = "Index";
      }
  
      &lt;h2&gt;Index&lt;/h2&gt;
  
      @using (Html.BeginForm())
      {
          @Html.HiddenFor(m =&gt; m.DummyDictionary);
          @Html.LabelFor(m =&gt; m.DummyDictionary["VT"].Name)
          @Html.TextBoxFor(m =&gt; m.DummyDictionary["VT"].Value)&lt;br /&gt;
          @Html.TextBoxFor(m =&gt; m.DummyDictionary["VT"].Token, new { @Value = Model.DummyDictionary["VT"].Token, style = "display:none;" })
          &lt;input type="submit" class="submit_button" /&gt;&lt;br /&gt;
      }
  </code></pre>
  
  <p><br>
  In the view I am using @Html.HiddenFor(m => m.DummyDictionary) to try to pass the dictionary over to the post method, but the dictionary is just empty. Without this @Html.HiddenFor the Dictionary in the post method is null.</p>
  
  <p><br>
  Thank you so much for the assistance I appreciate it!
  <br><br><br>
  <strong>UPDATE</strong><br></p>
  
  <h2>TheObject</h2>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
  
      namespace DummyMVC.Objects
      {
          public class TheObject
          {
              public string Name { get; set; }
              public string Value { get; set; }
              public string Token { get; set; }
          }
      }
  </code></pre>