title: Hidden input for Dictionary<string, string> in ASP.NET MVC 3
body: <p>I need to get my model properties in Post action, so need to hidden element for them, but I have a problem with type of <code>Dictionary &lt;string, string&gt;</code>. this is My model:</p>
  
  <pre><code>public class ViewModel{
   ...
   public ViewPart ViewPart { get; set; }
  }
  
  public class ViewPart {
   ...
   public Dictionary&lt;string, string&gt; Flags { get; set; }
  }
  </code></pre>
  
  <p>And My Controller: </p>
  
  <pre><code>Dictionary&lt;string, string&gt; flags = new Dictionary&lt;string, string&gt;();
  flags.Add("kind", "Edit");
  flags.Add("Command", "Save");
  ViewModel model = new ViewModel(){ Flags  = flags };
  return View(model);
  </code></pre>
  
  <p>In View: </p>
  
  <pre><code>@foreach(var item in Model.ViewPart.Flags) { 
   &lt;input type="hidden" id="ViewPart_Flags_@(item.Key)" value="@item.Value" name="ViewPart.Flags[@(item.Key)]" /&gt;
  }
  </code></pre>
  
  <p>Also I try This one :</p>
  
  <pre><code>@foreach(var item in Model.ViewPart.Flags) { 
    @Html.HiddenFor(modelItem =&gt; item)
  }
  </code></pre>
  
  <p><strong>Update</strong>
  Post Action:</p>
  
  <pre><code>[HttpPost]
  public ActionResult MyPostAction(ViewModel model){
    //model.ViewPart.Flags is null
  }
  </code></pre>
  
  <p>But in Post action the <code>Flags</code> is Always null, why? where is my fault? Is there any better way to pass variables from View To Action?</p>