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

微笑、不失礼 提交于 2019-12-05 21:30:50

问题


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?


回答1:


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.




回答2:


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

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



回答3:


Add the following code to your page, and the view engine will not apply the layout to it.

@{
    Layout = null;
}



回答4:


Views have this @{ View.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; }

and partial views don't




回答5:


I don't think there is any difference.



来源:https://stackoverflow.com/questions/3925574/difference-between-mvc-3-partial-page-razor-and-mvc-3-view-page-with-layout-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!