in C#

Script error when using RichTextEditor type in Razor macro – Umbraco

I came across this issue when trying to check if the RichTextEditor property had any content before rendering it to the display.

Examine the following code:

1
2
3
4
5
6
7
8
9
@{
var thisNode = Model;

}

@if (!string.IsNullOrEmpty(thisNode.MyRichContent))
{
<div class="text-widget">@thisNode.MyRichContent</div>
}

This causes a script error because Umbraco thinks MyRichContent is a object type.
To get around this, either call .ToString() on the property or do a length condition i.e thisNode.MyRichContent.ToString().Length > 0 to resolve the issue.