Html.ActionLink is very slow

I am using MVC 4 and Razor View Engine.

I have a call Html.ActionLink("Title", "Action")that is called in a foreach loop with ~ 200 elements, and it takes about 550 ms to complete. If I replace ActionLink with a simple string, it will take ~ 50 ms -> for Html.ActionLink it takes ~ 500 ms for 200 iterations!

Is there any way to speed this up?

I have 5 of them in my loop, so I need a page> 3s for ... The release of the assembly and the absence of the debug attribute in the web.config file do not help.

+5
source share
1 answer

I combined a few tips from the comments to achieve a reduction of ~ 3 s to ~ 250 ms to render a full page. The biggest changes:

  • (- > 2/3 )
  • "" :
      @{ var link = Html.ActionLink("_USER_", "Edit", new { id = "_ID_" }); } foreach - @link.Replace("_ID_", user.UserId.ToString()) ( String.Format, Html.ActionLink() escapes {0} to %7B0%7D
+4

All Articles