csharpfritz / csharp_with_csharpfritz

Show notes, slides, and samples from the CSharp with CSharpFritz show
MIT License
662 stars 215 forks source link

Cannot make new line character work inside a string (tried \n, \r\n , \u000A, $"{Environment.NewLine}" ) #112

Closed nakigoe closed 2 years ago

nakigoe commented 2 years ago

I cannot make a line break inside Blazor WebAssembly site navigation: \n, \r\n, \u000A $"{Environment.NewLine}" have no visual impact:

readonly public record struct Link (string Language, string Relative, string ShortName, string LongName, string Title);

public static readonly Link[] Services = new Link[]
{
    new Link("en","/services/translator.html",$"Russian \u21D4 English{Environment.NewLine} Translation","Russian \u21D4 English Bi\u2011directional Translation","Translation and Localization Services")
    .
    .
    .
    more links here
}

all suggestions are welcome

csharpfritz commented 2 years ago

Formatting a string using Razor means you are outputting HTML encoded content. To achieve a line-break in the rendered code, you will want to emit a
tag.

Blazor and Razor templates provide a layer of HTML-encoding on any string that should be rendered. To output a
tag, you need to use the Html.Raw method to encode properly: https://docs.microsoft.com/aspnet/core/mvc/views/razor?view=aspnetcore-6.0#expression-encoding

nakigoe commented 2 years ago

I've tried that one already, Blazor WebAssembly throws an error: The name 'Html' does not exist in the current context