MVC 3 部分页面 (Razor) 和 MVC 3 带布局的视图页面 (Razor) 之间的区别?
在 MVC 3 Beta 中,模板 MVC 3 Partial Page (Razor) 和 MVC 3 View Page with Layout (Razor) 之间有区别吗?
我向我的应用程序添加了一个部分页面 (_partialList)。现在,当我仅返回部分视图时,它会应用 _ViewStart.cshtml 中存在的布局 - 其行为非常类似于具有布局的标准视图页面。
if (Request.IsAjaxRequest())
return View("_partialList", someModelData);
“部分”页面如何与具有布局的标准视图页面区分开来?在任何特定情况下,两者的行为会有所不同吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您不想应用布局,请返回
PartialView
而不是View
:If you don't want to apply the layout return a
PartialView
instead ofView
:Darin 的回应解决了您不希望应用布局的实际问题。
关于两者之间的区别,在 Razor 中它们实际上是相同的,因为完整页面和部分页面都使用相同的扩展名并具有相同的基类。
之所以有不同的UI,是因为在Web Forms视图引擎中,两者是用不同的扩展和不同的基类实现的,这就是为什么需要单独的模板。
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.
将以下代码添加到您的页面中,视图引擎将不会对其应用布局。
Add the following code to your page, and the view engine will not apply the layout to it.
视图有这个
@{
View.Title = "索引";
布局=“~/Views/Shared/_Layout.cshtml”;
而
部分视图则不然
Views have this
@{
View.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
and partial views don't
我认为没有什么区别。
I don't think there is any difference.