Search code examples
c#asp.net-mvcinternationalizationhtml-helperactionlink

No characters from foreign languages while using ActionLink


When I use

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

Everything seems to be ok, but when I use this:

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

There are no all foreign characters. First one displays "żółć", second - "żółć". Why is that? How to fix it?


Solution

  • According to MSDN, Html.DisplayFor is intended to

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

    But your ActionLink is simply expecting a regular string to display as the link text.

    You better use DisplayNameFor() instead:

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

    See DisplayNameFor