What is Partial View?

8

Using the Controller I can return a Partial View , JSON, string and other things.

What is a Partial View? Is it heavily used in projects? Why use it?

    
asked by anonymous 18.10.2015 / 08:57

1 answer

10

It's a part of view , a part of the HTML code that will be generated. It works as if it were a control that would be inserted into the HTML with its own characteristics.

It is common to have complex pages where it would be difficult to mount everything as if it were one thing. We have adopted the technique of dividing and conquering. Each of these partial views takes care of a part of the content that will be rendered, forming the view

But this has another huge advantage. Updates can be made in a more granular way. When only part of the information is updated, it does not need to regenerate the whole view - obviously if the page is written in order to guarantee this, probably via AJAX.

Another obvious advantage is that it can be consumed by several different views .

You can have controllers / actions directly linked to these partial views or use them in controllers / actions that will generate other views . There is syntax for this. Of course they can consume their own models .

They do not have layout , only content matters.

Unless you are creating old-fashioned pages and very simple, it will certainly be very useful. So it can be said that it is used in almost all projects that propose to use MVC.

    
18.10.2015 / 14:01