title: pass dictionary data from view to controller
body: <p>A while ago, I was trying to pass a dictionary data from my view to my controller. And I was able to do so after googling on the net(remember it was one of Scott Hanselman's posts). The solution I had was something like</p>
  
  <pre><code>&lt;%for(int index=0; index&lt;Model.Count(); index++){
       var property= Model.ElementAt(index);%&gt;
       &lt;input type="hidden" name="&lt;%="properties["+index+"].Key"%&gt;"/&gt;
       &lt;input type="hidden" name="&lt;%="properties["+index+"].Value"%&gt;"/&gt;
  &lt;%}%&gt;
  
  public ActionResult Process(IDictionary&lt;string,string&gt; properties)
  {
        doSomething();
        return View();
  }
  </code></pre>
  
  <p>The code worked for awhile and then I did some refactoring and got rid of this chunk of code. Today, I ran into a situation in which I would like to pass a dictionary again. But no matter how hard I try, the <strong>properties</strong> parameter received by the action was always null. I tried the above code and </p>
  
  <pre><code>&lt;%for(int index=0; index&lt;Model.Count(); index++){
       var property= Model.ElementAt(index);%&gt;
       &lt;input type="hidden" name="&lt;%="properties.Keys["+index+"]"%&gt;"/&gt;
       &lt;input type="hidden" name="&lt;%="properties.Values["+index+"]"%&gt;"/&gt;
  &lt;%}%&gt;
  </code></pre>
  
  <p>Neither code worked. I googled again but couldn't find the post that helped me before. Can someone point out what I did wrong? thanks a million.</p>
  
  <p><strong>Update</strong>: It turned out that the problem is because the generated html code does not have continuous incrementing indexes. For instance, I was getting properties[0], properties[1], properties[3]...(properties[2] was missing). So, firebug would be your best friend when encountering this kind of problems.   </p>