显示来自不同文件夹的部分视图

Show partial view from different folder

是否可以访问放置在外部文件夹中的部分视图?


我想在页面上显示 _LoginPartial /Home/Index,但 _LoginPartial 应该在 /Auth 中。

当我尝试指定 /Home/Index 从 /Auth 获取此部分内容时,出现错误。

@Html.Partial("/Auth/Login")

ErrorLog 说

Message=The partial view 'Views/Auth/Login' was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Home/Auth/Login.aspx

~/Views/Home/Auth/Login.ascx

~/Views/Shared/Auth/Login.aspx

~/Views/Shared/Auth/Login.ascx

~/Views/Home/Auth/Login.cshtml

~/Views/Home/Auth/Login.vbhtml

~/Views/Shared/Auth/Login.cshtml

~/Views/Shared/Auth/Login.vbhtml

所以我知道它试图仅在 /Home 目录中找到我的部分。

使用部分视图的完整路径。

@Html.Partial("~/Views/Auth/Login.cshtml")