German Umlaute not displayed in <a> Tag when using variable at href in Razor Components
Describe the bug
When using a var at href instead of a literal string the umlaute (äüöß) in the text to show is not displayed correctly
To Reproduce
Steps to reproduce the behavior:
- Using this version of ASP.NET Core 3.0.100-preview-010184 [C:\Program Files\dotnet\sdk] in Visual Studio 2019 preview 2.2
- Run this code
-
in VS create a Blazor or RC project
-
in MainLayout.cshtml add:
-
@functions
{
string cLink = "https://docs.microsoft.com/en-us/aspnet/";
}
replace
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank" class="ml-md-auto">About</a>
with
<a href=@cLink target="_blank" class="ml-md-auto">äbout</a>
- See error
The link reads: äbout
Expected behavior
The link should read: äbout
If you replace the variable with the string in the anchor tag like
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank" class="ml-md-auto">äbout</a>
it is displaying correctly.
This was working in VS 17 and core 2.1
A possible solution would be to encapsulate your link text with MarkupString
Example
<a href=@cLink target="_blank" class="ml-md-auto">@(new MarkupString("äbout"))</a>
@sven5 Thank you - works regards Uwe
Thanks for contacting us, @uwefms.
@SteveSandersonMS, do we plan to handle this or the MarkupString approach suggested by @sven5 will be the way to go?
Thanks for reporting this!
This is a known issue in the components compiler, which we plan to fix. Your existing markup looks fine and will work as expected once the issue is fixed. Long term, there won't be a need to use MarkupString for this case, though it is a good workaround in the short term.
Closing as duplicate of https://github.com/aspnet/AspNetCore/issues/7147