加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在@ Html.ActionLink中放置@ Html.DisplayFor

发布时间:2020-12-16 07:12:16 所属栏目:asp.Net 来源:网络整理
导读:在asp.net mvc中,我有一个带有名称索引的视图,它将一个html表显示为网格. 假设这是我的html表: tabletr th Caption /th th/th/tr@foreach (var item in Model) {tr td @Html.DisplayFor(modelItem = item.Caption) /td td @Html.ActionLink("Edit","Edit",n
在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 => item.Caption)放在@Html.ActionLink的文本中(“编辑”,“编辑”,新{id = item.CityId})

但我从mvc给出一个错误.

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读