title: html encode/decode - ckeditor
body: <p>I am using ckeditor in a cshtml page to input content into my database that will later be displayed on a page with html tags to make the text easier to read. Since I am inputting the content through a textarea, I am getting a an error stating that the html tags that I am inputting <code>&lt;h1&gt;&lt;p&gt;</code> are potentially dangerous.</p>
  
  <p>To bypass this without turning RequestValidation to false, in my cinfig.js file I have set:</p>
  
  <pre><code>config.htmlEncodeOutput = true;
  </code></pre>
  
  <p>I am decoding the data from the database when displaying in my page.</p>
  
  <pre><code>@Html.Raw(System.Web.HttpUtility.HtmlDecode(row.Memo))
  </code></pre>
  
  <p>This works well. I only run into trouble when I attempt to edit the content from my database a second time.</p>
  
  <p>I am displaying in the editor like this:</p>
  
  <pre><code>&lt;textarea class="ckeditor" id="editor1" name="Memo" rows="25" cols="120"&gt;@Memo&lt;/textarea&gt;
  </code></pre>
  
  <p>With <code>@Memo</code> in the textarea, the current database content displays in the editor. The issue is that once the original text is sent to the database encoded, I believe that it is still encoded when re-displayed in the editor, when it needs to be decoded. So the editor treats the encoded tags as text and places new tags around the existing, which creates a mess.</p>
  
  <p>Any ideas would be greatly appreciated. Let me know if this needs more clarification.</p>
  
  <p>Thanks.</p>