asp.net-mvc-3markdownsharphtml.encode

Mvc3 Html.Encode and MarkdownSharp


I am using MarkdownSharp in an mvc3 project. The user is able to insert text into a textbox, that might be dangerous, so that he can write something like "2 < 3".

So I am not able to block all dangerous inputs.

To display the text, I want to encode all the dangerous characters with

Html.Encode(myString)

but this also encodes new-line and so on, so that after that I cannot use MarkdownSharp.


Solution

  • Could you please try:

    @Html.Raw(Html.Encode(myString).Replace("\n", "<br/>"))