调用@Html.Partial 显示属于不同控制器的局部视图 [英] Calling @Html.Partial to display a partial view belonging to a different controller
问题描述
我正在开发一个 ASP.NET MVC 3 应用程序,其内容页面具有通用的布局元素模式.但是,因为登录页面没有按照这个布局,所以我不能把这个布局放在ViewsShared\_Layout.cshtml
中.
I am developing an ASP.NET MVC 3 application, whose content pages have a common pattern of layout elements. However, because the login page does not follow this layout, I cannot place this layout in ViewsShared\_Layout.cshtml
.
所以我想添加另一个共享布局,例如 ViewsShared\_Content.cshtml
,并从内容视图中调用它...但不幸的是,这些视图属于不同的控制器.
So I would like to add another shared layout, say, ViewsShared\_Content.cshtml
, and call it from the content views... but unfortunately those views belong to different controllers.
有没有办法为属于不同控制器的视图调用 @Html.Partial
?
Is there any way to invoke @Html.Partial
for a view belonging to a different controller?
推荐答案
那没问题.
@Html.Partial("../Controller/View", model)
或
@Html.Partial("~/Views/Controller/View.cshtml", model)
应该可以.
如果你想通过(其他)控制器,你可以使用:
If you want to pass through the (other) controller, you can use:
@Html.Action("action", "controller", parameters)
或任何其他重载
这篇关于调用@Html.Partial 显示属于不同控制器的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!