Either method returns null. Is there a new data type I should be using? I also used IHtmlEncodedString, but that returns the data escaped (so can't be placed in a HTML view).
Any help would be very much appreciated. Thank you.
It looks like retrieving the value as an IHtmlEncodedString at least gets me the content, and doesn't return null. Now my issue is issuing the output in my view.
In the UmbracoViewPage.cs source code, there is a Write method that checks whether the input parameter is an IHtmlEncodedString, and if so, calls "WriteLiteral" on it. I'm wondering if I should be calling Write on each one of my model's properties (at least RTE/IHtmlEncodedString properties). This seems like an odd way to go about it, where in the previous versions I could just output the RTE content like:
I am finding in some cases that I need to retrieve RTE content as a HtmlString, other times as a string which I then must place in a HtmlString, and then other times I can retrieve IHtmlEncodedString and use it with no issue.
I am really not sure of the reason, but it seems like it may change based on whether the content is being used in a partial view, a view component, or directly in a template.
I manually map my published content to custom models, and the IHtmlEncodedString solution was not working for me whenever the content was output directly in a partial or ViewComponent.
My solution was to retrieve the RTE content as a string, then place inside a new HtmlString, such as:
Using this solution, I can output the HtmlString anywhere without needing to call @Html.Raw around the property. I'm not sure if Umbraco 9 is supposed to be used this way, and would love to know if there is an easier way for me to retrieve RTE content on a custom model, and be able to output that property without any additional ceremony.
Unable to access RTE content in Umbraco 9
In Umbraco v8, I would do the following to access RTE content:
In Umbraco v9, this is no longer working for me. I have tried the following:
Either method returns null. Is there a new data type I should be using? I also used IHtmlEncodedString, but that returns the data escaped (so can't be placed in a HTML view).
Any help would be very much appreciated. Thank you.
Hi John
Looks like it might be IHtmlEncodedString
It looks like retrieving the value as an IHtmlEncodedString at least gets me the content, and doesn't return null. Now my issue is issuing the output in my view.
In the UmbracoViewPage.cs source code, there is a Write method that checks whether the input parameter is an IHtmlEncodedString, and if so, calls "WriteLiteral" on it. I'm wondering if I should be calling Write on each one of my model's properties (at least RTE/IHtmlEncodedString properties). This seems like an odd way to go about it, where in the previous versions I could just output the RTE content like:
I am finding in some cases that I need to retrieve RTE content as a HtmlString, other times as a string which I then must place in a HtmlString, and then other times I can retrieve IHtmlEncodedString and use it with no issue.
I am really not sure of the reason, but it seems like it may change based on whether the content is being used in a partial view, a view component, or directly in a template.
I manually map my published content to custom models, and the IHtmlEncodedString solution was not working for me whenever the content was output directly in a partial or ViewComponent.
My solution was to retrieve the RTE content as a string, then place inside a new HtmlString, such as:
Using this solution, I can output the HtmlString anywhere without needing to call @Html.Raw around the property. I'm not sure if Umbraco 9 is supposed to be used this way, and would love to know if there is an easier way for me to retrieve RTE content on a custom model, and be able to output that property without any additional ceremony.
I used IHtmlEncodedString, but the code is output escaped (i.e. a paragraph tag is output as
Hi John,
I think you can fix that by inserting the rte content in @Html.Raw()
Best regards Frank
any advances/updates on this topic? im just trying to understand why umbraco doesn't use HtmlString from dotnetcore
thanks
I am still retrieving a string, and then placing in a HtmlString. I haven't found a better way to do this.
is working on a reply...