Open Closed

How to prevent Localize to output HTMLEncoded string when using razor pages #1850

mrall created

Im using the standard way to output localized content (@L["somekey"]) - this works fine, but when my textes contain html-tags the appear as text and are not interpreted as html.

I know thats the default behaviour of .net localization, but how can I out put the text "raw" without htmlencode?

kind regards

2 Answer(s)
  • 0
    EngincanV created
    Support Team

    Hi @mrall, probably you are using IHtmlLocalizer<MyResource> please change it to IStringLocalizer<MyResource>. After that change, your localization value won't be html-encoded, it will be view as raw text.

    @inject IStringLocalizer<MyResource>

  • 0
    mrall created


    according to the docs of IHtmlLocalizer and IStringLocalizer, the opposite is true,

    "Use the IHtmlLocalizer implementation for resources that contain HTML. IHtmlLocalizer HTML encodes arguments that are formatted in the resource string, but doesn't HTML encode the resource string itself."

    I tried your suggestion but that didn't solve my problem.

    The point is, that within Razor-Pages Text ouputted with the "@"-Operator always gets HTML-Encoded, so the solution to my problem was using "@Html.Raw(...)"


    That did the trick.