November Happy Hour will be moved to Thursday December 5th.

How to render long string as html content

Vote:
 

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..!

Thanks

Binay Thakur

#294767
Jan 16, 2023 12:22
Vote:
 

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

e.g. 

Content Model

Content View

Edit Mode Content Property

Rendered Page

#294777
Edited, Jan 16, 2023 15:25
Vote:
 

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 ?

Regards

Binay Thakur

#294828
Jan 17, 2023 11:00
Vote:
 

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;}

to 

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. 

    [UIHint(UIHint.Textarea)]
    [ScaffoldColumn(false)]
    public virtual string TestString { get; set; }

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

            return x; 
        }

        set
        {
            this.SetPropertyValue(p => p.TestXhtmlString, value);
        }
    }
#294829
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.