Skip to main content
added 12 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

A partial viewpartial view is used when you have some view component (optionally with it's own model) that is used in more than one place, or is better separated in to a separate file (for readability, for example). 

A sectionsection is placed in a master page, and allows individual views to populate those areas - they can mandatory or optional. There aren't really pro's and con's in a comparison between the two, since they serve different purposes.

For your menu example, you may have some mark-up that builds a menu (from a collection) which you would want to to use in many places, then a partial view would be the best option.

If you have a single menu on a page, whose contents change based on the page, then you might use a section to require that the view populates the menu (you may use a partial to populate that menu section too).

A partial view is used when you have some view component (optionally with it's own model) that is used in more than one place, or is better separated in to a separate file (for readability, for example). A section is placed in a master page, and allows individual views to populate those areas - they can mandatory or optional. There aren't really pro's and con's in a comparison between the two, since they serve different purposes.

For your menu example, you may have some mark-up that builds a menu (from a collection) which you would want to to use in many places, then a partial view would be the best option.

If you have a single menu on a page, whose contents change based on the page, then you might use a section to require that the view populates the menu (you may use a partial to populate that menu section too).

A partial view is used when you have some view component (optionally with it's own model) that is used in more than one place, or is better separated in to a separate file (for readability, for example). 

A section is placed in a master page, and allows individual views to populate those areas - they can mandatory or optional. There aren't really pro's and con's in a comparison between the two, since they serve different purposes.

For your menu example, you may have some mark-up that builds a menu (from a collection) which you would want to to use in many places, then a partial view would be the best option.

If you have a single menu on a page, whose contents change based on the page, then you might use a section to require that the view populates the menu (you may use a partial to populate that menu section too).

Source Link
Andy Hunt
  • 6k
  • 3
  • 37
  • 58

A partial view is used when you have some view component (optionally with it's own model) that is used in more than one place, or is better separated in to a separate file (for readability, for example). A section is placed in a master page, and allows individual views to populate those areas - they can mandatory or optional. There aren't really pro's and con's in a comparison between the two, since they serve different purposes.

For your menu example, you may have some mark-up that builds a menu (from a collection) which you would want to to use in many places, then a partial view would be the best option.

If you have a single menu on a page, whose contents change based on the page, then you might use a section to require that the view populates the menu (you may use a partial to populate that menu section too).