title: How can I make a loop to repeat my method for each item?
body: <p>there is my issue. In a controller, I have this method which export my view in a file when I click a button.</p>
  
  <pre><code>public ActionResult Export(string searchString, int searchOrder = 0)
  {
      var user = from m in db.Orders select m;
  
      if (!String.IsNullOrEmpty(searchString))
      {
          user = user.Where(s =&gt; s.ClientID.Contains(searchString));
      }
  
      Response.AddHeader("Content-Type", "application/vnd.ms-excel");            
      return this.View(user);
  }
  </code></pre>
  
  <p>My Index view :</p>
  
  <pre><code>@model IEnumerable&lt;MyApp.Models.Order&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Orders Historic&lt;/h2&gt;    
  
  &lt;div id="orderDiv"&gt;
  @using (Html.BeginForm("Export", "Historic", FormMethod.Get))
  {
              &lt;p&gt;
          Generate Order with ClientID :&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
           @Html.TextBox("searchString")
  
          &lt;input type="submit" value="GENEREMOI" /&gt;
          &lt;/p&gt;
  }
  &lt;/div&gt;
  </code></pre>
  
  <p>And my Export view :</p>
  
  <pre><code>@model IEnumerable&lt;KrysGroup.Models.Order&gt;
  
      &lt;table cellpadding="3" cellspacing="3"&gt;
          &lt;tr&gt;       
              &lt;td width="12%" align="center"&gt;
                  Client Name/ID
              &lt;/td&gt;
              &lt;td width="15%" align="center"&gt;
                  N° Order
              &lt;/td&gt;
  
              OTHER TD....
  
          &lt;/tr&gt;   
  
  @foreach (var item in Model)
  {
        TimeSpan result = DateTime.Now - item.OrderDate;
  
        if (result.Days &lt; 31)
        {            
              &lt;tr border="1" bgcolor="@Odd"&gt;
                 &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.Username) &lt;/td&gt;    
                 &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.OrderId) &lt;/td&gt;  
                  &lt;td&gt;
                      &lt;ul style="list-style-type:none; padding:0; margin:0"&gt;
                          @if (item.OrderDetails != null)
                          {
                              foreach (var o in item.OrderDetails)
                              {
                                  if (o.Pack == null)
                                  { 
                                      &lt;li&gt;  @Html.DisplayFor(modelItem =&gt; o.Product.Name)  &lt;/li&gt;
                                  }
                                  else
                                  {  
                                      &lt;li&gt; &lt;text&gt;Pack&lt;/text&gt;  @Html.DisplayFor(modelItem =&gt; o.Pack.Name)  &lt;/li&gt;
                                  }
                              }
                          }  
                      &lt;/ul&gt;             
                  &lt;/td&gt;
  
                  OTHER TD...    
   &lt;/table&gt;
  </code></pre>
  
  <p>So, in my view, I inform in a textbox a ClientID and when I click the button, it export in a file all the fields in my table with this ClientID. </p>
  
  <p>I would like to automate this action, that is to say I would like write a method or something for, when I click on the button, it executes this export() method for each clientId it meet in my table.</p>
  
  <p>I hope I was clear enough, sorry for my english..
  Thanks for your answers, links, tips whatever. </p>