41

Does anybody know what's the difference between Html.RenderAction and Html.Action?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Sasha
  • 20,424
  • 9
  • 40
  • 57
  • 1
    possible duplicate of [Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction](http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction) – Bellash Jul 18 '14 at 03:35

2 Answers2

37

Html.Action() – Outputs string

Html.RenderAction() – Renders directly to response stream

If the action returns a large amount of HTML, then rendering directly to the response stream provides better performance than outputting a string.

JTech
  • 3,420
  • 7
  • 44
  • 51
Megawolt
  • 589
  • 5
  • 19
  • 16
    So when would you use Html.Action if RenderAction gives better performance? –  Oct 19 '10 at 21:50
  • 3
    @user76071 from [another question](http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction) with Action you can put the result in a variable or return it from a function. – David Kassa Mar 04 '13 at 15:25
  • 1
    Better performance? Barely. This is a bad case of premature optimization. Unless you are outputting a huge wiki article, the differences are negligible. Personally, I find Html.Action more readable and only use Html.RenderAction if I am in a code block. – Jordan Jul 08 '16 at 12:52
  • Below article In answer below, states RenderAction is better when rendering a lot of HTML, (like a partial View.) That's why I like it better. – user1161391 Nov 30 '18 at 21:53
27

The difference between the two is that Html.RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html.Action returns a string with the result.

check out this link for a detailed explanation

VoodooChild
  • 9,776
  • 8
  • 66
  • 99