我的 Controller 中有一个名为 _AllLinks
的 [ChildActionOnly]
如果 _AllLinks.cshtml 位于我的 Controller 目录中,我可以使用 RenderAction,但如果我尝试将其放在 VIEWS 文件夹中的不同目录中,则无法使用它,如下所示
Html.RenderAction("_AllLinks", "Home", new { Model = Model, Area = "Core/List/" });
_AllLinks.cshtml
的位置为 Views/Core/Lists/
如果名为 _AllLinks 的 PartialView 位于不同的文件夹中,我如何调用 Html.RenderAction?
干杯
编辑
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
public ActionResult _AllLinks(List<Models.Links.MLink> Model)
{
return PartialView("~/Views/Core/Lists/_AllLinks", Model);
}
最佳答案
是的!你可以。您需要显式指定 View 的完整路径。
[ChildActionOnly]
public ActionResult _AllLinks(List<Models.Links.MLink> Model)
{
return PartialView("~/Views/Core/Lists/_AllLinks.cshtml",Model);
}
确保使用完整路径带文件扩展名 (.cshtml
)
此外,您还应该使用与操作方法签名匹配的路由值来调用 RenderAction。
<div>
@{ Html.RenderAction("_AllLinks", "Home", new {model = Model}); }
</div>
关于c# - HTML.RenderAction 来自不同位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46745259/