【问题标题】:putting @Html.DisplayFor in @Html.ActionLink将@Html.DisplayFor 放入@Html.ActionLink
【发布时间】:2013-01-02 15:16:11
【问题描述】:

在 asp.net mvc 中,我有一个带有名称索引的视图,它将一个 html 表显示为一个网格。 假设这是我的 html 表:

<table>
<tr>
    <th>
        Caption
    </th>
    <th></th>
</tr>
@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Caption)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.CityId }) |
        @Html.ActionLink("Details", "Details", new { id=item.CityId }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.CityId }) |
    </td>
</tr>
}
</table>

现在我想将@Html.DisplayFor(modelItem =&gt; item.Caption) 放在@Html.ActionLink("Edit", "Edit", new { id=item.CityId }) 的文本中

但我从 mvc 给出一个错误。

【问题讨论】:

  • 看什么是行不通的比看什么行得通更有帮助。向我们展示您尝试过的已损坏的代码。很可能只是在您的描述中包含了@ 符号,但很难说。
  • 我想使用这个@Html.ActionLink(@Html.DisplayFor(modelItem => item.Caption), "Edit", new { id=item.CityId })。错误说无法解析方法actionlink ..........

标签: asp.net-mvc razor html.actionlink


【解决方案1】:

只需使用正确的方法重载,如下所示:

@Html.ActionLink(item.Caption, "Edit", "Edit", new { id=item.CityId }, null)

【讨论】:

  • 很高兴能提供帮助! :)
猜你喜欢
  • 2013-10-26
  • 2010-12-30
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
  • 1970-01-01
  • 2013-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多