使用 ActionLink 时没有外语字符

No characters from foreign languages while using ActionLink

当我使用

@Html.DisplayFor(modelItem => item.Collection.Name)

一切似乎都很好,但是当我使用这个时:

@Html.ActionLink(@Html.DisplayFor(modelItem => item.Collection.Name) + "", "Index", new { })

没有全外文。第一个显示“żółć”,第二个显示“żółć”。这是为什么?如何解决?

根据 MSDNHtml.DisplayFor 旨在

Return HTML markup for each property in the object that is represented by the Expression expression.

但是您的 ActionLink 只是希望常规 string 显示为 link 文本。

你最好改用DisplayNameFor():

@Html.ActionLink(Html.DisplayNameFor(modelItem => item.Collection.Name).ToString(), "Index", new { })

DisplayNameFor