We are using Razor outside of the typical MVC flow. Our Razor views are called from within an XSL transform via a C# extension. The output of the Razor view is returned to the xsl transform as a string. In some cases we capture the result of a Razor view into an xsl variable and then pass that back out to our Model to be consumed as data in another Razor view. When this happens we end up with the first view being double encoded, once by Razor, the second time via the xsl transform. We need to be able to run Razor without having it encode the output.
Is this possible? How would we go about it?
Since you want to disable encoding in your entire view, your best bet would be to create your own view base class inheriting from
WebPageBase(and then your views should use@inheritsto specify your new type) and override theWrite(object value)method so that it callsWriteLiteral()instead. That way the output will not be encoded.