5

在 asp.net mvc 中,我有一个名为 index 的视图,它将一个 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 => item.Caption)输入@Html.ActionLink("Edit", "Edit", new { id=item.CityId })

但我从 mvc 给出一个错误。

4

1 回答 1

8

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

@Html.ActionLink(item.Caption, "Edit", "Edit", new { id=item.CityId }, null)
于 2013-01-18T20:29:31.393 回答