MVC 3部分页面(Razor)和MVC 3视图页面与布局(Razor)之间的区别?

时间:2021-07-02 15:12:15

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

在MVC 3 Beta中,模板MVC 3 Partial Page(Razor)和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.

我在我的应用程序中添加了一个部分页面(_partialList)。现在当我只返回局部视图时,它会应用_ViewStart.cshtml中的布局 - 非常像带有布局的标准视图页面。

    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?

“部分”页面如何与具有布局的标准视图页面区分开来?在任何特定情况下,两者的表现会不同吗?

5 个解决方案

#1


9  

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

Darin的回答解决了您不希望应用布局的实际问题。

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.

关于两者之间的差异,在Razor中它们实际上是相同的,因为完整页面和部分使用相同的扩展并具有相同的基类。

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.

之所以存在不同的UI,是因为在Web窗体视图引擎中,这两个实现了不同的扩展和不同的基类,这就是为什么分离模板是必要的。

#2


10  

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

如果您不想应用布局,请返回PartialView而不是View:

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

#3


3  

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

将以下代码添加到您的页面,视图引擎将不会将布局应用于您的页面。

@{
    Layout = null;
}

#4


2  

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

观点有这个@ {View.Title =“Index”; Layout =“〜/ Views / Shared / _Layout.cshtml”; }

and partial views don't

而部分观点则没有

#5


0  

I don't think there is any difference.

我认为没有任何区别。

#1


9  

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

Darin的回答解决了您不希望应用布局的实际问题。

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.

关于两者之间的差异,在Razor中它们实际上是相同的,因为完整页面和部分使用相同的扩展并具有相同的基类。

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.

之所以存在不同的UI,是因为在Web窗体视图引擎中,这两个实现了不同的扩展和不同的基类,这就是为什么分离模板是必要的。

#2


10  

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

如果您不想应用布局,请返回PartialView而不是View:

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

#3


3  

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

将以下代码添加到您的页面,视图引擎将不会将布局应用于您的页面。

@{
    Layout = null;
}

#4


2  

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

观点有这个@ {View.Title =“Index”; Layout =“〜/ Views / Shared / _Layout.cshtml”; }

and partial views don't

而部分观点则没有

#5


0  

I don't think there is any difference.

我认为没有任何区别。