title: Get value of dictionary<string, string> from hidden field to post method in asp.net mvc
body: <p>I am creating a web app in which I need to get the value of my <code>public Dictionary&lt;string, string&gt; KeyValuePairs { get; set; }</code> in post method </p>
  
  <p>here is how my code looks,</p>
  
  <p>My model -> <code>public Dictionary&lt;string, string&gt; KeyValuePairs { get; set; }</code></p>
  
  <p>the above property is included in my model</p>
  
  <pre><code>@{
      var index = 0;
      foreach (var item in Model.KeyValuePairs)
      {
          &lt;input type="hidden" value="@item.Key" name="@Model.KeyValuePairs.ElementAt(index).Key" /&gt;
          &lt;input type="hidden" value="@item.Value" name="@Model.KeyValuePairs.ElementAt(index).Value" id="@index" /&gt;
          index++;
      }
  }
  </code></pre>
  
  <p>I am storing all the key value of <code>Dictionary&lt;string, string&gt;</code> but still showing as empty in my controller post event,</p>
  
  <p>I also Tried Like below</p>
  
  <pre><code>@foreach (KeyValuePair&lt;string, string&gt; kvp in Model.KeyValuePairs)
  {
      &lt;input type="hidden" name="KeyValuePairs[@index].key" value="@kvp.Key" /&gt;
      &lt;input type="hidden" name="KeyValuePairs[@index].Value" value="@kvp.Value" /&gt;
      index++;
  }
  </code></pre>
  
  <p>What I need to do to get the Dictionary in Post</p>