How to prevent Razor from escaping an ampersand, such as in  ?

html, razor, razorengine

Solution

Use `@Html.Raw(model.Field)`.

It will prevent HTML encoding of your data (which happens by default since Razor v3).

See MSDN and this Quick Reference by Phil Haack.

update

I now see you're using RazorEngine. In RazorEngine you can just use the built-in Raw method like this: `@Raw(model.Field)`

Problem

I'm parsing a Razor template that contains code such as ``` @model.Field ``` When `Field` includes a ` `, it gets escaped and turns into ` `. How do I apply a real non-breaking space and prevent the escaping of `&`?

Original source