调用@ Html.Partial显示属于不同的控制器的局部视图 [英] Calling @Html.Partial to display a partial view belonging to a different controller

查看:794
本文介绍了调用@ Html.Partial显示属于不同的控制器的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个ASP.NET MVC 3应用程序,其内容的网页有布局元素的通用模式。但是,因为登录页面不遵循这个布局,我不能把这个布局在<$​​ C $ C> \\浏览\\共享\\ _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 \Views\Shared\_Layout.cshtml.

所以,我想补充的另一个共享的布局,比如说, \\浏览\\共享\\ _Content.cshtml ,并从内容的看法叫它......但不幸的是那些观点属于不同的控制器。

So I would like to add another shared layout, say, \Views\Shared\_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆