【问题标题】:How to add a Model Primary Key which is INT, to an ActionLink LinkText如何将 INT 的模型主键添加到 ActionLink LinkText
【发布时间】:2014-07-25 12:58:29
【问题描述】:

我正在尝试添加一个 ActionLinnk,其中文本将是 Persons ID。但是,我收到一个错误说“无法将 int 转换为字符串”

这是因为 Fullname 是一个字符串

 @Html.ActionLink(item.FULLNAME, "Edit", new { id = item.ID })

这不是因为 ID 是一个 INT。

 @Html.ActionLink(item.ID, "Edit", new { id = item.ID })

我尝试用引号括起来,但没有运气。我也可以使用 razor 转换为字符串,然后将其添加回来,但我认为这应该很简单。谢谢

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    只需将其转换为字符串

    @Html.ActionLink(item.ID.ToString(), "Edit", new { id = item.ID })
    

    【讨论】:

    • 该死的......我很尴尬!!我是 MVC 新手,但不是 ASP.net !!!非常感谢
    猜你喜欢
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    相关资源
    最近更新 更多