title: Render Razor View as string resulted in extra formatting tags (tabs, line-breaks)? How to remove?
body: <p>I've asked this question as a comment on another post but couldn't get it to work. I'm using <a href="https://stackoverflow.com/a/2759898/248480">RenderRazorViewToString() method</a>, but somehow the JSON that get returned got all the Visual studio formatting with it (tabs, white spaces, line-breaks, etc...), here's what I've done:</p>
  
  <pre><code>public virtual ActionResult RenderToString()
  {
      var html = RenderRazorViewToString(MVC.Markets.Views._RenderToString);
      return Json(new { html = html }, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>Here's the result that got returned:</p>
  
  <pre><code>{"html": "&lt;div class=\"frame company-quote contain\" data-module-name=\"FirstGlanceModule\"&gt;\r\n\t&lt;div data-module-name=\"CompanyHeaderModule\"&gt;\r\n\t\t&lt;h1&gt;\r\n\t\t\tMicrosoft Corp &lt;em&gt;(MSFT:NASDAQ)&lt;/em&gt;&lt;/h1&gt;\r\n\t&lt;/div&gt;\r\n\t&lt;div class=\"first-glance\" data-module-name=\"FirstGlanceQuoteModule\"&gt;\r\n\t\t&lt;table&gt;\r\n\t\t\t&lt;thead&gt;\r\n\t\t\t\t&lt;tr&gt;\r\n\t\t\t\t\t&lt;th&gt;\r\n\t\t\t\t\t\tPrice\r\n\t\t\t\t\t&lt;/th&gt;\r\n\t\t\t\t\t&lt;th&gt;\r\n\t\t\t\t\t\tChange\r\n\t\t\t\t\t&lt;/th&gt;\r\n\t\t\t\t\t&lt;th&gt;\r\n\t\t\t\t\t\tVolume\r\n\t\t\t\t\t&lt;/th&gt;\r\n\t\t\t\t\t&lt;th&gt;\r\n\t\t\t\t\t\tMarket Cap\r\n\t\t\t\t\t&lt;/th&gt;\r\n\t\t\t\t&lt;/tr&gt;\r\n\t\t\t&lt;/thead&gt;\r\n\t\t\t&lt;tbody&gt;\r\n\t\t\t\t&lt;tr&gt;\r\n\t\t\t\t\t&lt;td&gt;\r\n\t\t\t\t\t\t$30.13\r\n\t\t\t\t\t&lt;/td&gt;\r\n\t\t\t\t\t&lt;td&gt;\r\n\t\t\t\t\t\t&lt;span class=\"neg\"&gt;-0.13&lt;/span&gt;\r\n\t\t\t\t\t&lt;/td&gt;\r\n\t\t\t\t\t&lt;td&gt;\r\n\t\t\t\t\t\t32.75 M\r\n\t\t\t\t\t&lt;/td&gt;\r\n\t\t\t\t\t&lt;td&gt;\r\n\t\t\t\t\t\t$252.77 B\r\n\t\t\t\t\t&lt;/td&gt;\r\n\t\t\t\t&lt;/tr&gt;\r\n\t\t\t&lt;/tbody&gt;\r\n\t\t&lt;/table&gt;\r\n\t&lt;/div&gt;\r\n\t&lt;div class=\"controls\" data-module-name=\"FirstGlanceControlsModule\"&gt;\r\n\t\t&lt;em&gt;Data as of February 15, 2012 01:59:59 PM ET&lt;/em&gt;\r\n\t\t&lt;div&gt;\r\n\t\t\t&lt;button class=\"type-1\"&gt;\r\n\t\t\t\t&lt;span&gt;Add to Watchlist&lt;/span&gt;&lt;/button&gt;\r\n\t\t\t&lt;button class=\"type-2\"&gt;\r\n\t\t\t\t&lt;span&gt;Trade&lt;/span&gt;&lt;/button&gt;\r\n\t\t&lt;/div&gt;\r\n\t&lt;/div&gt;\r\n&lt;/div&gt;\r\n"}
  </code></pre>
  
  <p>I've tried to add an extension method <a href="http://www.yetanotherchris.me/home/2009/9/9/formatting-xml-in-c.html" rel="nofollow noreferrer">outlined here</a> to reformat this into xml with Formatting.None and got a slightly better result, but still have extra tags as well as the xml version tag which I probably don't want:</p>
  
  <pre><code>{"html": "&lt;?xml version=\"1.0\" encoding=\"utf-16\"?&gt;&lt;div class=\"frame company-quote contain\" data-module-name=\"FirstGlanceModule\"&gt;&lt;div data-module-name=\"CompanyHeaderModule\"&gt;&lt;h1&gt;\r\n\t\t\tMicrosoft Corp &lt;em&gt;(MSFT:NASDAQ)&lt;/em&gt;&lt;/h1&gt;&lt;/div&gt;&lt;div class=\"first-glance\" data-module-name=\"FirstGlanceQuoteModule\"&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;\r\n\t\t\t\t\t\tPrice\r\n\t\t\t\t\t&lt;/th&gt;&lt;th&gt;\r\n\t\t\t\t\t\tChange\r\n\t\t\t\t\t&lt;/th&gt;&lt;th&gt;\r\n\t\t\t\t\t\tVolume\r\n\t\t\t\t\t&lt;/th&gt;&lt;th&gt;\r\n\t\t\t\t\t\tMarket Cap\r\n\t\t\t\t\t&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;\r\n\t\t\t\t\t\t$30.13\r\n\t\t\t\t\t&lt;/td&gt;&lt;td&gt;&lt;span class=\"neg\"&gt;-0.13&lt;/span&gt;&lt;/td&gt;&lt;td&gt;\r\n\t\t\t\t\t\t32.75 M\r\n\t\t\t\t\t&lt;/td&gt;&lt;td&gt;\r\n\t\t\t\t\t\t$252.77 B\r\n\t\t\t\t\t&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=\"controls\" data-module-name=\"FirstGlanceControlsModule\"&gt;&lt;em&gt;Data as of February 15, 2012 01:59:59 PM ET&lt;/em&gt;&lt;div&gt;&lt;button class=\"type-1\"&gt;&lt;span&gt;Add to Watchlist&lt;/span&gt;&lt;/button&gt;&lt;button class=\"type-2\"&gt;&lt;span&gt;Trade&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"}
  </code></pre>
  
  <p>Any idea on how to make this work? Thanks.</p>