4

I am simply looking for how these two are different and what are their pros and cons?

It seems you can do all with partial views that you can do with templates.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
Andrei
  • 4,122
  • 3
  • 22
  • 24
  • Question has nothing to do with Razor or MVC3 specifically, so I modified the title and keywords – Erik Funkenbusch Jan 22 '11 at 00:35
  • I am sorry, but have you just modified the question to fit your answer? =) Pls, see the following link(that is what I was talking about): http://stackoverflow.com/questions/4383554/asp-net-mvc-3-razor-templates-vs-renderpartial – Andrei Jan 24 '11 at 03:09

2 Answers2

6

If you are referring to EditorTemplates (rather than inline timeplates), then there are some big differences. First, partial views require you to specify your view when you use them, while templates work on the type of the data object.

Second, because templates work on data types, then when you make a change to the template, it changes it everywhere that type is used, not just where the partial view is used (this can be a disadvantage as well in some cases).

Third, templates are passed additional information that partial views are not, in particular you recieve Model Metadata, such as that created by attributes.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Don't you get ModelMetadata on partials too? I thought ModelMetadata was a property of ViewData, and not specific to Display & Editor templates. – danludwig Jan 22 '11 at 01:16
  • @olivehour - Yes, the property is there, but it's null when you access it from a view or partial. It's only populated in templates. – Erik Funkenbusch Jan 22 '11 at 04:41
0

if you mean "inline helpers", they are simply an easier way of building the equivalent of HtmlHelper extension methods - but they are only for use in the specific view. partial views, on the other hand, can have more logic behind them (via their controller) without violating MVC and they can be easily reused from multiple views

Robert Levy
  • 28,747
  • 6
  • 62
  • 94