title: ASP.NET MVC Html.Encode - New lines
body: <p><code>Html.Encode</code> seems to simply call <code>HttpUtility.HtmlEncode</code> to replace a few html specific characters with their escape sequences.</p>
  
  <p>However this doesn't provide any consideration for how new lines and multiple spaces will be interpretted (markup whitespace). So I provide a text area for the a user to enter a plain text block of information, and then later display that data on another screen (using <code>Html.Encode</code>), the new lines and spacing will not be preserved.</p>
  
  <p>I think there are 2 options, but maybe there is a better 3rd someone can suggest.</p>
  
  <p>One option would be to just write a static method that uses HtmlEncode, and then replaces new lines in the resulting string with <code>&lt;br&gt;</code> and groups of multiple spaces with <code>&amp;nbsp;</code></p>
  
  <p>Another option would be to mess about with the <code>white-space: pre</code> attribute in my style sheets - however I'm not sure if this would produce side effects when Html helper methods include new lines and tabbing to make the page source pretty.</p>
  
  <p>Is there a third option, like a global flag, event or method override I can use to change how html encoding is done without having to redo the html helper methods?</p>