I am building a webstie in multiple languages and would like the asp-action
to be customised depending on the language. The idea is that the URL in the English version is something like /en/feedback
whilst in German it should be /de/gaestestimmen
.
I have tried the following:
<a asp-controller="Home"
asp-action="@Localizer["navKontakt"]"
asp-route-lang="@CultureInfo.CurrentCulture.TwoLetterISOLanguageName">
@Localizer["navFeedback"]
</a>
The Localizer returns the correct text in the second instance, but not for the asp-action
- there it returns:
"Microsoft.AspNetCore.Mvc.Localization.LocalizedHtmlString
" instead of the expected string.
If I just enter asp-action="Feedback"
it works fine.
Anyone any idea how I can make this work?
Found the answer. As the localizer retuns a LocalizedHtmlString which is an object but not a string, I have to add the .Value to get value as a string.
asp-action="@Localizer["navKontakt"].Value"
Looks like a quotes issue. Try switching out the double quotes for the attribute value with single quotes:
<a asp-controller="Home"
asp-action='@Localizer["navKontakt"]'
asp-route-lang="@CultureInfo.CurrentCulture.TwoLetterISOLanguageName">
@Localizer["navFeedback"]
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With