5

in asp.net mvc, I have a view with name index that show one html table as a grid. suppose this is this my html table:

<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>

now I want put @Html.DisplayFor(modelItem => item.Caption) in the text of @Html.ActionLink("Edit", "Edit", new { id=item.CityId })

but i give an error from mvc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pezhman Parsaee
  • 1,209
  • 3
  • 21
  • 35
  • Seeing what doesn't work will be more helpful than seeing what does work. Show us the code that you tried that's broken. It's likely just the inclusion of the `@` symbol from your description, but hard to say. – Eli Gassert Jan 18 '13 at 20:17
  • 1
    i want to use this @Html.ActionLink(@Html.DisplayFor(modelItem => item.Caption), "Edit", new { id=item.CityId }). error say cannot resolve method actionlink ......... – Pezhman Parsaee Jan 18 '13 at 20:40

1 Answers1

8

Just use the correct method overload, like this:

@Html.ActionLink(item.Caption, "Edit", "Edit", new { id=item.CityId }, null)
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480