When should partial views be used in asp.net mvc?

I went through an asp.net mvc nerd sample application for dinner ... But still can't figure out where and when should I go for partial views?

  • Is it compatible with usercontrols in webformw?

Note: It would be useful to see a partial view in action ... Any sample ...

+7
asp.net-mvc partial-views
source share
4 answers

Everything that you would use more than once. For example, on this page for SO, you see a list of related messages on the right. This is done on several pages, so why create them several times. You can transfer data in a partial view to customize it based on certain criteria.

I don’t like things like login, where I prefer to go to the login page. However, this scenario is used frequently.

+7
source share

You should use partial views in two main cases:

  • If you need to reuse a similar “group of components” in several places on the website (for example, the “login form” can be used in different places on the website).

  • When you have significant rendering logic for creating a specific section of a page and you want to isolate it so that the page is cleaner / easily edited normally in the same way, your own method or class. A good example is the navigation bar, in which you want to have logic to display the navigation bar in one place, although only your Site.Master could name it.

+12
source share

Particles should be used when you need to display similar information in several views.

A simple selection will be partial, which displays a list of orders. On the invoice summary page, you must use partial to show recent orders. On the order list page, you can use the same fragment to display all the orders that have ever been placed.

+1
source share

Keep in mind that the partial parts of Mvc 2 do not support binding state through partial ones, such as EditTemplates. This can be useful in some situations and disappointing in others. If you want the binding state to be designed as it is in the templates, check the MvcContribs view types.

0
source share

All Articles