title: How to add a calculated "ID" to a button in a @foreach loop - ASP.NET Web Pages Razor
body: <p>I have a @foreach loop for a blog displaying all posts on my page. I have a button at the bottom of each post and when clicked I want that particular post to animate. My logic is within my @foreach loop to add a different ID to each button so I can perform an animation depending on which post is selected...please help</p>
  
  <pre><code>@{
  
  
      foreach(var post in posts){
          &lt;div class="userPosts"&gt;
              @post.FirstName&lt;br /&gt;&lt;br /&gt;
              @post.LastName&lt;br /&gt;&lt;br /&gt;
              @post.Subject&lt;br&gt;&lt;br&gt;
             &lt;button id=""&gt;click here&lt;/button&gt;
          &lt;/div&gt;
  
      }
      }
  </code></pre>