Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 Partial View vs. Regular View

Just curious if there was anything that made a partial view different from a regular view other than convention.

Code-wise they look and work similar but I was curious if there was a difference (other than specifying the template page, etc at the top).

like image 383
Steve Sloka Avatar asked Oct 04 '11 14:10

Steve Sloka


People also ask

What is the difference between view and partial view?

Views are the general result of a page that results in a display. It's the highest level container except the masterpage. While a partial view is for a small piece of content that may be reused on different pages, or multiple times in a page.

What is difference between partial and RenderPartial?

The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.

What is the purpose of a partial view?

A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.

What is advantage of partial view in MVC?

Partial View can be a parent view and we can use it as a parent view of any partial view. We can simply pass Model to show data in the partial view or we can send the data in the partial view with the help of AJAX call.


1 Answers

If you're using Razor, there is no real difference between a partial view and a view, they're both cshtml files. A view is a view. If you want to use a view as a partial view, then there are some restrictions, such as not using a Layout file.

In WebForms View engine, a partial view is typically an ascx, versus an aspx. There are some subtle differences there in the definitions, but they're still largely interchangeable.

Partial versus full is all about the way it's used. If you return the view in a View() method, it's a full view. If you return it in a Partial, then it's a partial.

like image 110
Erik Funkenbusch Avatar answered Sep 21 '22 18:09

Erik Funkenbusch