2

Inside of my View page I have the following line:

@Model.RenderedMarkdown

RenderedMarkdown is generated with the following:

var renderer = new MarkdownSharp.Markdown();
return renderer.Transform(Markdown);

Now for this example, let's just say that Markdown was this:

###test

which will change into this:

<h3>test</h3>

However what is being rendered on my page is this:

&lt;h3&gt;test&lt;/h3&gt;

Is there a setting somewhere to turn off this automatic encoding?

JustinN
  • 896
  • 1
  • 14
  • 28

1 Answers1

2

Try this:

@Html.Raw("<h3>test</h3>")

Put your variable to Raw helper.

Something like this:

@Html.Raw(Model)

Added:

Thanks to mythz and his comment:

There is also an T.AsRaw() extension method. Which basically just wraps the string into a MvcHtmlString which doesn't get escaped.

webdeveloper
  • 17,174
  • 3
  • 48
  • 47
  • Unfortunately that resulted in the same thing, I think ServiceStack is automatically changing the content before it hits the View page. – JustinN Oct 22 '12 at 07:33
  • @JustinN Set brake point in action or use `@Html.TextAreaFor()` to view your content. – webdeveloper Oct 22 '12 at 07:44
  • @JustinN Interesting question about `MarkdownSharp`: [Why isn't MarkdownSharp encoding my HTML?](http://stackoverflow.com/questions/4864255/why-isnt-markdownsharp-encoding-my-html) – webdeveloper Oct 22 '12 at 08:03
  • I'll give that a go this evening, this specific bit of code is on my laptop which I didn't bring to the office today. Interesting read though, and might be the fix as I did have the code prefixed with some text on the same line (simply for testing purposes) – JustinN Oct 22 '12 at 11:01
  • There is also an `T.AsRaw()` extension method. Which basically just wraps the string into a **MvcHtmlString** which doesn't get escaped. @webdeveloper can you update your answer to include this? – mythz Oct 22 '12 at 17:26
  • @mythz Of course, could you provide link to msdn with example? I had never used this extension. Thanks! – webdeveloper Oct 22 '12 at 18:13
  • @webdeveloper it's an extension inside ServiceStack - mythz created ServiceStack. AsRaw() worked! The line breaks however did not... update your answer and I'll mark it as accepted :) – JustinN Oct 22 '12 at 19:48
  • @JustinN Thanks, I understand now. Found his answer with example: http://stackoverflow.com/questions/12586343/servicestack-net-mini-profiler-in-razor-view – webdeveloper Oct 22 '12 at 19:59