aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

German Umlaute not displayed in <a> Tag when using variable at href in Razor Components

Open uwefms opened this issue 7 years ago • 4 comments

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:

  1. Using this version of ASP.NET Core 3.0.100-preview-010184 [C:\Program Files\dotnet\sdk] in Visual Studio 2019 preview 2.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">&auml;bout</a>

  1. See error

The link reads: &auml;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">&auml;bout</a>

it is displaying correctly.

This was working in VS 17 and core 2.1

uwefms avatar Feb 11 '19 12:02 uwefms

A possible solution would be to encapsulate your link text with MarkupString

Example <a href=@cLink target="_blank" class="ml-md-auto">@(new MarkupString("&auml;bout"))</a>

sven5 avatar Feb 11 '19 13:02 sven5

@sven5 Thank you - works regards Uwe

uwefms avatar Feb 11 '19 13:02 uwefms

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?

mkArtakMSFT avatar Feb 11 '19 18:02 mkArtakMSFT

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

SteveSandersonMS avatar Feb 11 '19 19:02 SteveSandersonMS