I'm using @Html.Action()
to render a child action within my view.
我正在使用@ Html.Action()在我的视图中呈现子动作。
The _ViewStart.cshtml
file specifies that all views should use a particular layout like this:
_ViewStart.cshtml文件指定所有视图都应使用如下特定布局:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Problem is, that layout is getting applied to my child action too, so the final page ends up with two headers and two footers. How do I prevent this?
问题是,该布局也适用于我的子操作,因此最终页面最终会有两个页眉和两个页脚。我该如何防止这种情况?
2 个解决方案
#1
22
2 possibilities:
2种可能性:
-
return PartialView()
from the corresponding controller action instead of areturn View()
从相应的控制器操作返回PartialView()而不是返回View()
-
Blank out the layout in the view itself
在视图中删除布局
@{ Layout = null; }
#2
0
Seems you want to use ChildActionOnly
and don't want to pass the model from view then you can not user PartialView.
似乎你想使用ChildActionOnly并且不想从视图传递模型然后你不能使用PartialView。
If it is so, you need to remove the layout manually
如果是这样,则需要手动删除布局
@{
Layout = "";
}
#1
22
2 possibilities:
2种可能性:
-
return PartialView()
from the corresponding controller action instead of areturn View()
从相应的控制器操作返回PartialView()而不是返回View()
-
Blank out the layout in the view itself
在视图中删除布局
@{ Layout = null; }
#2
0
Seems you want to use ChildActionOnly
and don't want to pass the model from view then you can not user PartialView.
似乎你想使用ChildActionOnly并且不想从视图传递模型然后你不能使用PartialView。
If it is so, you need to remove the layout manually
如果是这样,则需要手动删除布局
@{
Layout = "";
}