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

标签 c# .net razor asp.net-core

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

相关文章:

c# - 检查一个 IEnumerable 是否包含另一个 IEnumerable 的所有元素

c# - 为什么进程会丢失线程?

c# - 如何重构重载方法

javascript - 基于下拉选择的显示/隐藏控件 mvc 4 razor c#

javascript - 使用 Html.BeginCollectionItem 时 MVC AutoComplete EditorFor

asp.net-mvc-3 - ASP.NET MVC3 - Html.TextBoxFor 和 autofocus 属性

c# - "The specified type member ' 日期 ' is not supported in LINQ "

c# - 何时调用 base.method() 以及 base.method() 中应包含哪些代码?

javascript - 使用 jQuery 将无序列表所选项目传递到 ASP.NET Web 窗体

c# - .NET API 更新包括 ID