views:

194

answers:

3

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?

A: 

I don't think there is any difference.

stackunderflow
Any idea why they exist ?
Preets
+2  A: 

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

if (Request.IsAjaxRequest())
    return PartialView("_partialList", someModelData);
Darin Dimitrov
@Darin Dimitrov, Thank you, I wasn't aware of that.
Preets
But I am still not sure why two templates exist when they basically do the same thing (i.e. the partial view / page with layout)?
Preets
+1  A: 

Darin's response solves your practical issue of not wanting the layout to be applied.

Regarding the difference between the two, in Razor they are practically the same because both full pages and partials use the same extension and have the same base class.

The reason why there is different UI is because in the Web Forms view engine the two are implemented with different extensions and different base classes, which is why to seperate templates are necessary.

marcind
Preets
@Preets The WebForms view engine has no implication for Razor at runtime. However, the Visual Studio tooling (the Add View dialog) supports both view engines and therefore requires that Razor comes with 2 options even though they are currently functionally equivalent.
marcind
@marcind, thanks :) I would never have figured that out !
Preets