title: c# razor mvc textboxfor in foreach loop
body: <p>how is it possible to retrieve data from <code>TextBoxFor</code> helper within a foreach loop? I mean:</p>
  
  <p>in the view:</p>
  
  <pre><code>foreach(Language l in ViewBag.Languages){
      &lt;td&gt;@l.lang&lt;/td&gt;
      &lt;td&gt;@Html.TextBoxFor(model =&gt; model.Name)
  }
  </code></pre>
  
  <p>and how can I retrieve it in the controller once posted?</p>
  
  <pre><code>MyModel.Name //this returns the value of the first textbox within the foreach loop
  </code></pre>
  
  <p>By the way model.Name is defined in MyModel.cs as:</p>
  
  <pre><code>public string Name { get; set; }
  </code></pre>