我如何能有一个视图呈现部分(用户控件)从不同的文件夹? 有了预览3,我习惯用完整的路径调用RenderUserControl,但升级到预览5,这是不可能的了。 相反,我们得到了RenderPartial方法,但它没有提供我所寻找的功能。


当前回答

尝试使用RenderAction("myPartial","Account");

其他回答

对于名为myPartial的用户控件。ascx位于Views/Account文件夹,如下所示:

<%Html.RenderPartial("~/Views/Account/myPartial.ascx");%>

只需要包含视图的路径和文件扩展名。

剃须刀:

@Html.Partial("~/Views/AnotherFolder/Messages.cshtml", ViewData.Model.Successes)

ASP。NET引擎:

<% Html.RenderPartial("~/Views/AnotherFolder/Messages.ascx", ViewData.Model.Successes); %>

如果这不是你的问题,你能包括你的代码,用来与RenderUserControl工作吗?

你应该试试这个

~/Views/Shared/parts/UMFview.ascx

将~/Views/放在代码之前

VirtualPathProviderViewEngine是WebFormsViewEngine的基础,它应该支持路径前面的“~”和“/”字符,所以上面的例子应该可以工作。

我注意到你的例子使用了路径“~/Account/myPartial”。ascx”,但是您提到您的用户控件在Views/Account文件夹中。你试过了吗

< %。RenderPartial(“~点击量/ Html / myPartial . ascx”);% >账户

还是你的问题打错了?

尝试使用RenderAction("myPartial","Account");