title: MVC Html.ActionLink and Url.Action slow to render during Debug mode in Visual Studio
body: <p><strong>tl;dr</strong> Displaying a view in MVC with lots of records and 4 rendered links per record takes a long time to load while running in debug mode in VS2012.</p>
  
  <p>I have an ASP.NET MVC4 web application and one of the views displays a table of 300 records. Whenever I run the application in debug mode in VS2012, it takes nearly 2 minutes to load this view. The table has 4 unique links being generated either by HTML.ActionLink or URL.Action. From testing, I know the generation of these links is the offending code.</p>
  
  <p>Example of slow code:</p>
  
  <pre><code>&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;Bob&lt;/td&gt;
          &lt;td&gt;
      Tony
              &lt;div style="margin-top: 5px;"&gt;
                  &lt;a href="@Url.Action("Edit", "Home", new { id = item.Id })" class="btn btn-mini" title="Edit"&gt;&lt;i class="icon-edit"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;a href="@Url.Action("Details", "Home", new { id = item.Id })" class="btn btn-mini" title="Details"&gt;&lt;i class="icon-file"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;a href="@Url.Action("Delete", "Home", new { id = item.Id })" class="btn btn-mini" title="Delete"&gt;&lt;i class="icon-trash"&gt;&lt;/i&gt;&lt;/a&gt;
              &lt;/div&gt;
              &lt;div style="margin-top: 5px;"&gt;
                  @Html.ActionLink("Do Something", "SomeAction", "SomeController", new { id = item.Id }, new { @class = "btn btn-success btn-mini", data_pe_type = "auto" })
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      }
  &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p>If I modify the code and build the base part of the links outside the foreach, the time to load reduces to 15 seconds.</p>
  
  <p>Example of faster code:</p>
  
  <pre><code>&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      @{
          var editLink = Url.Action("Edit", "Home") + "/";
          var detailsLink = Url.Action("Details", "Home") + "/";
          var deleteLink = Url.Action("Delete", "Home") + "/";
          var saLink = Url.Action("SomeAction", "SomeController") + "/";
      }
      @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;Bob&lt;/td&gt;
          &lt;td&gt;
      Tony
              &lt;div style="margin-top: 5px;"&gt;
                  &lt;a href="@editLink@item.Id" class="btn btn-mini" title="Edit"&gt;&lt;i class="icon-edit"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;a href="@detailsLink@item.Id" class="btn btn-mini" title="Details"&gt;&lt;i class="icon-file"&gt;&lt;/i&gt;&lt;/a&gt;
                  &lt;a href="@deleteLink@item.Id" class="btn btn-mini" title="Delete"&gt;&lt;i class="icon-trash"&gt;&lt;/i&gt;&lt;/a&gt;
              &lt;/div&gt;
              &lt;div style="margin-top: 5px;"&gt;
                  &lt;a href="@saLink@item.Id" class="btn btn-success btn-mini" data-pe-type="auto"&gt;Do Something&lt;/a&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      }
  &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p>I'm using IIS Express and have tested this in both IE10 and Chrome 27 on Windows 7. In Chrome I have IPv6 disabled. This only happens during debug. I also had a co-worker test the same code on their machine and they encounter the same problem.</p>
  
  <p>I've solved the performance problem by moving the base link generation outside the foreach, but now would like to know why Debugging caused my original code to render so slowly.</p>