Friday, October 24, 2014

Sitecore MVC output rich text field as HTML

One problem I came across when outputting Sitecore template fields (of rich text aka HTML) was that the HTML tags would be encoded and displayed on the page. To fix this, placing Html.Raw around the field value, would then output it correctly in HTML.
@Html.Raw(RenderingContext.Current.Rendering.Item.Fields["HTML Content"])
The example above outputs the 'HTML Content' Rich Text field directly as HTML. This field is a member of the content template which was set as the associated content (data source) for the rendering.

No comments:

Post a Comment