title: Why doesn't my List<string> bind to a series of hidden fields when using Html.Hidden()?
body: <p>I'm trying to use the default model binder in asp.net mvc to bind a list of hidden fields</p>
  
  <pre><code>&lt;input id="entity" name="entity" type="hidden" value="/string/one/here" /&gt;
  &lt;input id="entity" name="entity" type="hidden" value="/another/string/here" /&gt;
  &lt;input id="entity" name="entity" type="hidden" value="/last/string/here" /&gt;
  </code></pre>
  
  <p>To a <code>List&lt;string&gt;</code> like this:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Move(List&lt;string&gt; entity)
      {
          return View(entity);
      }
  </code></pre>
  
  <p>When I post the form, the view displays the contents of the list like this:</p>
  
  <pre><code>        &lt;%foreach (string item in Model)
            {%&gt;
  
            &lt;%: Html.Hidden("entity", item)%&gt;
            &lt;!--binding not working correctly --&gt;
  
          &lt;%} %&gt;
  </code></pre>
  
  <p>And the generated content is this:</p>
  
  <pre><code>&lt;input id="entity" name="entity" type="hidden" value="/last/string/here" /&gt;
  &lt;input id="entity" name="entity" type="hidden" value="/last/string/here" /&gt;
  &lt;input id="entity" name="entity" type="hidden" value="/last/string/here" /&gt;
  </code></pre>
  
  <p>I'm confuseled. I tried changing the initial hidden field to this:</p>
  
  <pre><code>&lt;input id="entity__" name="entity[]" type="hidden" value="/string/one/here" /&gt;
  &lt;input id="entity__" name="entity[]" type="hidden" value="/another/string/here" /&gt;
  &lt;input id="entity__" name="entity[]" type="hidden" value="/last/string/here" /&gt;
  </code></pre>
  
  <p>But when I tried posting that I got this error:</p>
  
  <pre><code> System.NullReferenceException: Object reference not set to an instance of an object.
  </code></pre>
  
  <p>on this line of code in the view:</p>
  
  <pre><code>&lt;%foreach (string item in Model)
  </code></pre>
  
  <p>I've been able to bind list of strings before... without using an index in the name. I don't understand why this isn't working correctly. Maybe a fresh set of eyes could help me out with this?</p>
  
  <p>Thanks</p>
  
  <h2>edit</h2>
  
  <p>In continuing to expirement. I ditched the HtmlHelper and hardcoded a hidden field inside the <code>foreach</code> loop like this:</p>
  
  <pre><code>&lt;%foreach (string item in Model)
    {%&gt;
        &lt;input id="entity" name="entity" type="hidden" value="&lt;%:item %&gt;" /&gt;
  &lt;%} %&gt;
  </code></pre>
  
  <p>This <b>worked</b>. I have no idea what the difference is between the Html helper's code and this so I put the two side by side and tried to match them up.</p>
  
  <pre><code>&lt;input id="entity" name="entity" type="hidden" value="//Content/files/NewDirectory/Aesculuparviflora011cm.jpg" /&gt;
  &lt;input id="entity" name="entity" type="hidden" value="//Content/files/NewDirectory/Aesculuparviflora011cm.jpg" /&gt;
  </code></pre>
  
  <p>They are identical. But the binding works when I hardcode tags and it doesn't work when i use the html helper. What gives?????????</p>