@Html.ActionLink 项目名称为 link

@Html.ActionLink with the item Name as a link

我在一件最终必须很简单的事情上遇到了困难。 使用 @Html.ActionLink ,我想要的只是一个 link 以及 table.

上模型中的名称文本

这是我正在做的事情:

<td data-th="Nome">@Html.ActionLink( @item.Name , "Details", new { id = @item.UserID })</td>

但我收到错误:

HtmlHelper has not 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 3+ 版本

@Html.ActionLink( @item.Name , "Action_Name", "Controller_Name" , new { id = @item.UserID }, null)

@Html.ActionLink( @item.Name , "Action_Name", "Controller_Name" , new { @item.UserID }, null)

在 mvc 3+ 版本中不再需要 ID

当您尝试在扩展方法中传递动态变量时会发生此问题。这是不支持的。

您可能遇到以下情况之一:

  1. 您的 Name 属性 是一个动态变量。您可以尝试将其转换为 string(string) @item.Name
  2. 您忘记在视图顶部添加模型:@model MyModel