gpt4 book ai didi

.net - 使用 @Html.ActionLink() 时出错

转载 作者:行者123 更新时间:2023-12-02 10:40:38 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Html.ActionLink cannot be dynamically dispatched

(1 个回答)


8年前关闭。




得到如下错误..

Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'ActionLink' 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.



在 MVC 应用程序中,我尝试使用字典条目的键作为链接的链接文本,但出现错误。

这是我遇到错误的那一行……我也尝试用 @item.Key 和其他各种方式替换 item.Key。
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)

我的整个 View 代码看起来像这样......
<form id="ViewFiles" method="post"  action="Index">
<ul>
@foreach (var item in @ViewBag.filesFolders)
{
if (item.Value == "folder")
{
<li>
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)
</li>
}
else if (item.Value == "file")
{
<li><a href="">FILES-@item.Key</a></li>
}
}
</ul>
</form>

最佳答案

类型类型转换 item.Key串起来

@Html.ActionLink((string)item.Key,"ExpandFolder","Home",new {path=item.Key },null)

关于.net - 使用 @Html.ActionLink() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19208346/

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