gpt4 book ai didi

c# - 来自不同位置的 HTML.RenderAction?

转载 作者:太空宇宙 更新时间:2023-11-04 15:54:42 25 4
gpt4 key购买 nike

我的 Controller 中有 [ChildActionOnly],名为 _AllLinks

如果 _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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com