thematt
thematt

Reputation: 185

Sitecore Multiline Text field, convert string to html

I am using C# MVC Razor.

Question:

I have a Multiline Text field with HTML, I use this field because I want no formatting at all. I just want to output the raw value.

example:

<path d="M610.7 357.9c-2.4-1.2-16.6-8.6-18.7-9.7 -7.5-3.8-10.1-7.2-10.1-12.9 0-8 6.5-13.1 16.7-13.1 6 0 11.7 2.6 15.1 4.5 0.6 0.3 1.3 0.5 2.1 0.5 2.4 0 4.3-1.9 4.3-4.3 0-1.6-0.9-3-2.2-3.7 -4.3-2.4-11.5-5.6-19.3-5.6 -14.9 0-25.3 8.9-25.3 21.7 0 11.5 7.5 16.9 14.9 20.7 2.1 1.1 16.5 8.5 18.7 9.6 5.7 3 8.9 7.5 8.9 12.6 0 6.9-5.9 14.3-16.7 14.3 -10.5 0-18.7-7.1-21-9.2l-0.7-0.6 -6.4 5.8 0.8 0.7c2.8 2.8 13.2 12 27.3 12 15.8 0 25.3-11.6 25.3-22.9C624.3 369.9 619.3 362.5 610.7 357.9z" />

Normally it outputs as:

&lt;path d="M610.7 357.9c-2.4-1.2-16.6-8.6-18.7-9.7 -7.5-3.8-10.1-7.2-10.1-12.9 0-8 6.5-13.1 16.7-13.1 6 0 11.7 2.6 15.1 4.5 0.6 0.3 1.3 0.5 2.1 0.5 2.4 0 4.3-1.9 4.3-4.3 0-1.6-0.9-3-2.2-3.7 -4.3-2.4-11.5-5.6-19.3-5.6 -14.9 0-25.3 8.9-25.3 21.7 0 11.5 7.5 16.9 14.9 20.7 2.1 1.1 16.5 8.5 18.7 9.6 5.7 3 8.9 7.5 8.9 12.6 0 6.9-5.9 14.3-16.7 14.3 -10.5 0-18.7-7.1-21-9.2l-0.7-0.6 -6.4 5.8 0.8 0.7c2.8 2.8 13.2 12 27.3 12 15.8 0 25.3-11.6 25.3-22.9C624.3 369.9 619.3 362.5 610.7 357.9z" /&gt;

So I wrapped the value in:

@WebUtility.HtmlDecode(complexShapes)

With no change. How can I get this value as is?

Upvotes: 1

Views: 2094

Answers (2)

hutchonoid
hutchonoid

Reputation: 33306

If your model values are set as follows in your controller:

model.ComplexShapes = 
     "<path d=\"M610.7 357.9c-2.4-1.2-16.6-8.6-18.7-9.7 -7.5-3.8-10.1-7.2-10.1-12.9 0-8 6.5-13.1 16.7-13.1 6 0 11.7 2.6 15.1 4.5 0.6 0.3 1.3 0.5 2.1 0.5 2.4 0 4.3-1.9 4.3-4.3 0-1.6-0.9-3-2.2-3.7 -4.3-2.4-11.5-5.6-19.3-5.6 -14.9 0-25.3 8.9-25.3 21.7 0 11.5 7.5 16.9 14.9 20.7 2.1 1.1 16.5 8.5 18.7 9.6 5.7 3 8.9 7.5 8.9 12.6 0 6.9-5.9 14.3-16.7 14.3 -10.5 0-18.7-7.1-21-9.2l-0.7-0.6 -6.4 5.8 0.8 0.7c2.8 2.8 13.2 12 27.3 12 15.8 0 25.3-11.6 25.3-22.9C624.3 369.9 619.3 362.5 610.7 357.9z\" />";

You can simply use @HtmlRaw to output it:

@Html.Raw(Model.ComplexShapes)  

Screen Grab

**Screen Grab**

Working Fiddle

Upvotes: 1

Mark Cassidy
Mark Cassidy

Reputation: 5860

Difficult to say without seeing your code that actually handles the field value and returns it.

Normally you would do something like this:

return new HtmlString(myFieldValue);

to instruct the framework that the string is ready to present as-is.

Upvotes: 0

Related Questions