Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Murray Roke 486 posts 908 karma points c-trib
    May 18, 2022 @ 04:47
    Murray Roke

    Why IHtmlEncodedString instead of HtmlString or IHtmlString?

    In a vanilla v9 project I would output content from an RTE like so:


    In a vanilla v8 project I would do this:


    The v9 way seems error-prone and a waste of everyone's keystrokes.

    This is because a (non-standard) Umbraco.Cms.Core.Strings.IHtmlEncodedString is used in v9 where a System.Web.IHtmlString was used in v8

    Can we change back to the v8 way?

  • Dave Woestenborghs 3495 posts 12101 karma points MVP 7x admin c-trib
    May 18, 2022 @ 07:10
    Dave Woestenborghs

    Hi Murray,

    I'm not using Html.Raw for displaying RTE fields. That works just fine for me.


  • Daniël Knippers 149 posts 1111 karma points MVP 2x c-trib
    May 18, 2022 @ 09:08
    Daniƫl Knippers

    The only thing to be aware of is you need to have @inherits UmbracoViewPage<TModel> in your view instead of just @model TModel since Umbraco applies some custom logic to IHtmlEncodedString and will ensure there it's written without encoding again, see the source. Not sure why Umbraco doesn't just use ASP.NET Core's IHtmlString though and wanted to come up with their own version, looks like they serve the same purpose.

  • Murray Roke 486 posts 908 karma points c-trib
    May 19, 2022 @ 01:45
    Murray Roke

    We are trying to use it in a partial view. ...oh I didn't realise you could use @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyModel> in a partial view.
    yea that works.
    It still seems a bit odd not to use HtmlString.

Please Sign in or register to post replies

Write your reply to: