What are the differences between editor templates and partial views?

I'm just looking for how these two are different, and what are their pros and cons?

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

+4
source share
2 answers

If you mean EditorTemplates (and not built-in templates), then there are some big differences. First, partial views require you to specify your view when using them, and templates work on the type of data object.

Secondly, since templates work with data types, then when you make changes to a template, it changes it wherever this type is used, and not only where a partial view is used (this can be a drawback, in some cases) .

Thirdly, additional information is transmitted to the templates that there are no partial representations, in particular, you get model metadata, such as created by attributes.

+6
source

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

0
source

Source: https://habr.com/ru/post/1336514/


All Articles