Html.Encode
seems to simply call HttpUtility.HtmlEncode
to replace a few html specific characters with their escape sequences.
However this
If you use Razor you can do:
@MvcHtmlString.Create(Html.Encode(strToEncode).Replace(Environment.NewLine, "
"))
in your view, or in your controller:
HttpServerUtility httpUtil = new HttpServerUtility();
MvcHtmlString encoded = httpUtil.HtmlEncode(strToEncode).Replace(Environment.NewLine, "
");
I have not tested the controller method, but it should work the same way.