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 503 posts 966 karma points c-trib
    May 18, 2022 @ 04:47
    Murray Roke
    0

    Why IHtmlEncodedString instead of HtmlString or IHtmlString?

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

    @Html.Raw(Model.BodyText)
    

    In a vanilla v8 project I would do this:

    @Model.BodyText
    

    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 3504 posts 12135 karma points MVP 9x admin c-trib
    May 18, 2022 @ 07:10
    Dave Woestenborghs
    0

    Hi Murray,

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

    Dave

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

    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 503 posts 966 karma points c-trib
    May 19, 2022 @ 01:45
    Murray Roke
    0

    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.

  • andrew shearer 510 posts 659 karma points
    Aug 24, 2023 @ 22:35
    andrew shearer
    0

    still unsure why Umbraco doesn't use the core HtmlString datatype?

Please Sign in or register to post replies

Write your reply to:

Draft