title: How i can generate dynamic id for text field and get data from array of model in asp.net 4 mvc3
body: <p>This is my first post here! :)</p>
  <p>I have to return an array of my model from my controller class to the view page. I want to put the data into a text box and generate dynamic id's for each text box to use the data further via JavaScript (that's why I am looking for dynamic id's).</p>
  <h1>Model</h1>
  <pre><code>public partial class BhBuyerChart
  {
      public string Date { get; set; }
      public string Quantity { get; set; }
  
      public BhBuyerChart(string n, string d)
      {
          Date = n;
          Quantity = d;
      }
  }
  </code></pre>
  <hr />
  <h1>Controller</h1>
  <pre><code>public ActionResult test()
  {
       BhBuyerChart[] model = new BhBuyerChart[7];
  
       DataTable dt = (DataTable)ExecuteDB(ERPTask.AG_GetAllShipmentRecord, CurrentUserId);
       List&lt;BhBuyerChart&gt; ItemList = null;
       ItemList = new List&lt;BhBuyerChart&gt;();
       int i = 0;
       foreach (DataRow dr in dt.Rows)
       {
           model[i] = new BhBuyerChart(dr[&quot;Shipmentdate&quot;].ToString(), dr[&quot;ShipmentQuantity&quot;].ToString());
           i++;
       };
  
       return View(model);
  }
  </code></pre>
  <hr />
  <h1>View</h1>
  <h2>1st Attempt</h2>
  <pre><code>&lt;div&gt;
      &lt;% for (int i=0; i&lt;2; i++) {%&gt;
      &lt;%: Html.TextBoxFor(m =&gt; m[i].Quantity, new { id = &quot;Quantity&quot;})%&gt;    &lt;%--value can assign from model but dnt know how to assing dynamic id --%&gt;
  
      &lt;input type=&quot;text&quot; value=&quot;&lt;%= i %&gt;&quot; id=&quot;text&lt;%=i %&gt;&quot;/&gt;                 &lt;%--dynamic id can be assinged dnt knw how to assing model value here in textbox --%&gt;
      &lt;% } %&gt;
  &lt;/div&gt;
  </code></pre>
  <h2>2nd Attempt</h2>
  <pre><code>&lt;div&gt;
  &lt;% int i = 0; %&gt;
  &lt;% foreach (ERP.Domain.Model.BhBuyerChart user in Model) {  %&gt;
        &lt;% i++; %&gt;
        &lt;input type=&quot;text&quot;; id=&quot;textbox&lt;% i %&gt;&quot; ; value=&quot;&lt;% user.Quantity %&gt;&quot; /&gt;   
   &lt;% } %&gt;
   &lt;/div&gt;
  </code></pre>
  <hr />
  <p>I really appreciate everybody's attention and help and I look forward to your responses!</p>