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

标签 c# html asp.net-mvc razor

我的 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/

相关文章:

c# - 当测试并行运行时,FakeItEasy 有时无法创建假货

C# - 传递一个可能在其他地方改变的 bool 值,但我不想改变方法

html - 用线性渐变着色后将图像定位在 div 中

html - 使用绝对位置列出过早换行的元素

Asp.Net Mvc 突出显示当前页面链接技术?

c# - DbContext 已被释放

c# - WPF 中的自定义控件与 Winforms 中一样必要吗?

c# - 将 TimeSpan.TotalMilliseconds 转换为 long

javascript - 自定义元素升级时如何执行脚本

asp.net-mvc - 当依赖属性更改值时,删除/添加 requiredif 的星号