title: ASP.NET MVC Passing Raw HTML from Controller to View
body: <p>I have been scratching my head about this for a few days, and I am not sure if it is an issue with my environment or the code itself basing this on being to ASP.NET MVC (although I have 5 years experience in C#). I am using a recent clean install of Win7x64 and VS 2008 with all the patches.</p>
  
  <p>I have raw HTML stored in a database table that is selectively loaded by the controller based on a few rules which I do not have control over. Unfortunately when attempt to stuff the value into a view data in the control like such:</p>
  
  <pre><code>ViewData["HTMLData"] = DAO.HTMLDataGet();
  </code></pre>
  
  <p>When I see the output, it is escaped/HTML Encoded. I tried using the following all of which did not seem to resolve this issue:</p>
  
  <pre><code>&lt;%: HttpUtility.HtmlDecode(ViewData["HTMLData"].ToString())%&gt;
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>&lt;%: Server.HtmlDecode(ViewData["HTMLData"].ToString())%&gt;
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>&lt;%: Html.Raw(ViewData["HTMLData"].ToString())%&gt;
  </code></pre>
  
  <p>...it grabs the raw HTML from the database table just fine, however it keeps forcing that blasted encoding regardless of what I try. From what I read on the MSDN, there was a foot note about problems resulting from HTML not being decoded properly that contained spaces (which mine does). Since I doubt I am the only one who has faced this I am turning to you folks for some ideas.</p>
  
  <p>I am about to Kludge my way though it with a regex in the view to do page cleanup, but thought it would be better to get some advice from some other folks first before I brute force it.Thanks in advance.</p>