简体   繁体   中英

MVC4 / Is a partial view what I want?

My site is based off of the MVC4 Web Application with Razor. I would like to divide up the page into areas such as:

-----------------------
|      |              |
|      |              |
|      |--------------|
|      |              |
|      |              |
|------|              |
|      |              |
|      |              |
|      |--------------|
|      |              |
|      |              |
-----------------------

What is this called? Is each area a "Partial View"? I need the correct terminology so I can google for more help.

A partial view is simply the rendering of a view without the layout (by default), with or without a view model.

I would recommend to not confuse the functionality of a partial view and the layout of page. A partial view can return any subset of html including a fully rendered page. So in your example, the entire column on the left could be a partial view, that then calls two partial views to render the top and bottom. Or the partial view could return the top and bottom.

Partial views are good for displaying content that may be out of the context of the current context (for example pulling up a modal popup with order details from an order list screen using Ajax). I personally use Partial Views to separate the display of each of my viewmodels for the parent view (page or partial view).

As for a page layout, I would highly recommend reading ScottGU's Blog on Layout and Sections where a layout can require or optionally have sections that pages fill-in .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM