Razor encodes string by default. Is there any special syntax for rendering without encoding?
Since ASP.NET MVC 3, you can use:
|
|||||||||
|
|
|||||
|
As well as the already mentioned @Html.Raw(string) approach, if you output an MvcHtmlString it will not be encoded. This can be useful when adding your own extensions to the HtmlHelper, or when returning a value from your view model that you know may contain html. For example, if your view model was:
then
|
|||
|
The MvcHtmlString class also offers a static method to create html strings:
|
|||
|
Use
Then you have peace of mind that you haven't created a potential security hole and any special/foreign characters are displayed correctly in all browsers. |
|||
|