title: ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
body: <p>I have some list. I would like to change one or more values inside of it by using <code>Lambda Expressions</code> in Razor code especially with <code>ForEach</code> loop.</p>
  
  <p>I don't know, It is possible or not, But my curiosity is more high to do with ForEach. <strong><em>I have to do this in Razor code not in the controller:</em></strong></p>
  
  <p>I take a reference from this <a href="https://stackoverflow.com/questions/12986776/change-some-value-inside-the-listt/12986795#12986795">Answer</a>, <strong>BUT TRIED THE SAME SYNTAX IN RAZOR CODE:</strong></p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.months, new SelectList(Model.myList.Where(s =&gt; s.value == "1").ToList().ForEach(s =&gt; s.value = "January"), "id", "value")})
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Controller Code:</p>
  
  <pre><code>List&lt;Digit&gt; myList = bindMonth(12);
  
  public static List&lt;Digit&gt; bindMonth(int maxvalue)
  {
     List&lt;Digit&gt; monthList = new List&lt;Digit&gt;();
     maxvalue = maxvalue + 1;
     for (int i = 0; i &lt; maxvalue; i++)
       {
           monthList.Add(new Digit(i, i.ToString()));
       }
      return monthList;
  }
  
  public class Digit
  {
      public int id { get; set; }
      public string value { get; set; }
      public Digit(int id, string value)
      {
         this.id = id;
         this.value = value;
      }
  }
  </code></pre>
  
  <p>It's throwing me <em>Compilation Error</em> in Browser.</p>
  
  <p><a href="https://i.stack.imgur.com/AjFhH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AjFhH.png" alt="enter image description here"></a></p>
  
  <p>Any help will be appreciated..!!!</p>