gpt4 book ai didi

c# - 使用变量来引用局部 View 的位置

转载 作者:行者123 更新时间:2023-11-30 23:11:11 26 4
gpt4 key购买 nike

我是 asp.net core 的新手,正在尝试在 ASP.Net Core 应用程序中呈现局部 View 。分部 View 的地址在运行时确定。我构建了一个 View 模型,它从 Controller 解析到 View 中并包含所需的文件地址。

以下代码会引发以下编译器错误:

@Html.Partial(Model.File);

Error CS1973 'IHtmlHelper' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

如有任何帮助,我们将不胜感激。

最佳答案

最终的解决方案是在 Razor 文件中指定类型。以下行有效:

@Html.Partial((string) Model.File)

关于c# - 使用变量来引用局部 View 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44876308/

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