Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent escaping html in Razor (standalone)?

I have a Model with property Content which contains HTML string.

var model = new { Content = ... } Razor.Parse(templateBody, model) 

How can I render this string using standalone Razor.

I tried:

@(new HtmlString(Model.Content)) 

and also

@(HttpUtility.HtmlDecode(Model.Content)) 

Model.Content renders always HTML-escaped.

like image 201
Exta Avatar asked Mar 07 '13 14:03

Exta


People also ask

Why is HTML escaping?

Escapes are very useful for representing characters that are not apparent or are ambiguous. Numeric or named character references, as well as CSS escapes, can be used to represent characters in HTML style attribute. The style element HTML can not contain numeric or named character references.

How do you escape Razor syntax?

In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.

What is razor in HTML?

Razor is a markup syntax for embedding . NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.


1 Answers

this should work Html.Raw(Model.Content)

like image 175
Wahid Bitar Avatar answered Sep 20 '22 02:09

Wahid Bitar