0

I have ten or more view where I could use this:

@Html.Partial("_Stats")

or:

20-30 lines of HTML code in my every view.

Does the @Html.Partial() bring in code at compile or run time? If at run time then is there a performance overhead for rendering the partial and should I bother about it ?

Angela
  • 3,269
  • 3
  • 22
  • 24

2 Answers2

1

Premature optimisation is a root of all evil!! Do use partials as you pleased, don't worry about the performance just yet. Worry about it when your app halts with million hits a day. Probably one request to DB costs more than a few partials includes.

Community
  • 1
  • 1
trailmax
  • 34,305
  • 22
  • 140
  • 234
0

Use @{Html.RenderPartial("_Stats");}, it works faster.

webdeveloper
  • 17,174
  • 3
  • 48
  • 47
  • Can you explain the difference. I didn't know about this. – Angela Sep 14 '12 at 09:25
  • There is no difference between @Html. and @{Html. } apart from notation – trailmax Sep 14 '12 at 09:27
  • Thanks for down voting. [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). Also look at [ASP MVC Compile-time include of partial view](http://stackoverflow.com/questions/8920250/asp-mvc-compile-time-include-of-partial-view) – webdeveloper Sep 14 '12 at 09:31
  • Your links are talking about Partial vs RenderPartials and don't provide any evidence that RenderPartials will be quicker, only suggestion from Darin. And in fact, Html.Partial is just a wrapper for Html.RenderPartial. – trailmax Sep 14 '12 at 09:42
  • Try to make benchmark yourself and you will see difference. Question is taking about more then ten partials. With rising of partial count you will better results. I also agree with this article: [ASP.NET MVC - Html.Partial vs Html.RenderPartial](http://info.titodotnet.com/2011/10/aspnet-mvc-htmlpartial-vs.html) "RenderPartial is a bit faster" – webdeveloper Sep 14 '12 at 10:00