Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MVC 3 Partial Page (Razor) and MVC 3 View Page with Layout (Razor)?

In MVC 3 Beta, is there a difference between the templates MVC 3 Partial Page (Razor) and MVC 3 View Page with Layout (Razor) ?

I added a partial page (_partialList) to my application. Now when I return only the partial view, it applies the Layout present in _ViewStart.cshtml - acting very much like a stardard view page with layout.

    if (Request.IsAjaxRequest())
        return View("_partialList", someModelData);

How does a "partial" page distinguish itself from a standard view page with layout ? Will the two behave differently in any particular scenario?

like image 538
Preets Avatar asked Oct 13 '10 15:10

Preets


People also ask

What is difference between layout and partial view in MVC?

A layout is something that we can include once in a single page and we can use the same layout to any number of pages. A partial view is something that we can include the same content any number of times in a single page(where it is required) and can be used in any number of pages.

What is view and partial view in MVC?

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 partial view in Razor pages?

Partial Pages or Views are Razor files containing snippets of HTML and server-side code to be included in any number of pages or layouts. Partial pages can be used to break up complex pages into smaller units, thereby reducing the complexity and allowing teams to work on different units concurrently.

What is difference between partial and render partial view?

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.


1 Answers

If you don't want to apply the layout return a PartialView instead of View:

if (Request.IsAjaxRequest())
    return PartialView("_partialList", someModelData);
like image 104
Darin Dimitrov Avatar answered Oct 07 '22 11:10

Darin Dimitrov