Answered by:
How can I insert <br/> element and variable inside localizer of blazor sever-side?

Question
-
User1052024640 posted
I followed the tutorial(https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-3.1) to achieve Localization in blazor server-side. All works well.
Now here is a variable:
string Money="123";
And here is the text in the Localizer:
Hi, I got @Money . <br/> What a happy day.
I consider it should be:
Hi, I got 123.
What a happy day.
Well, it turns out to be like this:
Hi, I got @Money . <br/> What a happy day.
The variable and the <br/> element doesn't work any.
How can I solve this? Thank you.
Tuesday, July 21, 2020 8:42 AM
Answers
-
User1052024640 posted
Well, I solved it.
I should do it like this:
The text in Localizer:
Hi, I got {0}. <br/> What a happy day.
In the razor page:
@((MarkupString)Localizer["GotMoney",Money].Value)
Then it works.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 21, 2020 12:07 PM
All replies
-
User475983607 posted
The default Razor behavior encodes HTML characters to protect the application from malicious scripts. You must opt-in to render raw HTML.
@Html.Raw("This is a <br /> line break test")
Tuesday, July 21, 2020 11:17 AM -
User1052024640 posted
Html.Raw does not exist in Blazor.
I search for it and finally found the MarkupString(https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.markupstring.value?view=aspnetcore-3.1) replaced it in blazor.
However, MarkupString worked with the <br/> element while not worked with the variable.
Tuesday, July 21, 2020 11:57 AM -
User1052024640 posted
Well, I solved it.
I should do it like this:
The text in Localizer:
Hi, I got {0}. <br/> What a happy day.
In the razor page:
@((MarkupString)Localizer["GotMoney",Money].Value)
Then it works.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 21, 2020 12:07 PM -
User475983607 posted
Sorry, in Blazor it's
<div> @((MarkupString)"This is a <br /> line break test") </div>
Tuesday, July 21, 2020 12:55 PM