SaaS CMS has officially launched! Learn more now.

How to render long string as html content


Hi Team,

    I have to render the long string as html cotent. Suppose if i will add <b>Hello</b> and <img src="image url" alt="image" width="500" height="600">. It should be display Hello as bold text and image in the page. I have tried XhtmlString property and @Html.Raw() in the view but It is not working.

Any help would be highly appreciated..!


Binay Thakur

Jan 16, 2023 12:22

I have tried this on Alloy Sample Site and using HTML.Raw worked for me 


Content Model

Content View

Edit Mode Content Property

Rendered Page

Edited, Jan 16, 2023 15:25

Hi Minesh Shah (Netcel)

  Thank you for your response.

  It is working for me also. But i wanted to use XhtmlString or TinyMCE controls.

  Do you have any reference for XhtmlString or TinyMCE controls ?


Binay Thakur

Jan 17, 2023 11:00

I'm a little confused you have a string property currently on the content type, do you want to change this to an XhtmlString ? Or do you want to  cast the content to an XhtmlString and than use PropertyFor ? 

If you want to change 

public virtual string TestProperty {get; set;}


public virtual XhtmlString TestProperty {get; set;}

My advice would be to create a new XhtmlProperty with a custom getter which gets the Data from the original property if Null and also hide the original property from the editors e.g. 

    public virtual string TestString { get; set; }

    public virtual XhtmlString TestXhtmlString
            var x = this.GetPropertyValue(p => p.TestXhtmlString);
            if (x == null)
                return new XhtmlString(TestString);

            return x; 

            this.SetPropertyValue(p => p.TestXhtmlString, value);
Edited, Jan 17, 2023 11:21
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.