Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

putting @Html.DisplayFor in @Html.ActionLink

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.

like image 309
Pezhman Parsaee Avatar asked Jan 18 '13 20:01

Pezhman Parsaee


1 Answers

Just use the correct method overload, like this:

@Html.ActionLink(item.Caption, "Edit", "Edit", new { id=item.CityId }, null)
like image 72
Leniel Maccaferri Avatar answered Oct 26 '22 16:10

Leniel Maccaferri