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.

2
  • Question has nothing to do with Razor or MVC3 specifically, so I modified the title and keywords Commented Jan 22, 2011 at 0: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): stackoverflow.com/questions/4383554/… Commented Jan 24, 2011 at 3:09

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Don't you get ModelMetadata on partials too? I thought ModelMetadata was a property of ViewData, and not specific to Display & Editor templates.
@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.
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

1 Comment

No, he's referring to the "EditorFor" and "DisplayFor" template system.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.