2

I have a snippet <h2>SomeText</h2>

When I saved in database from ckeditor change to it: &lt;h2&gt;SomeText&lt;/h2&gt;

now when I am using @WebUtility.HtmlDecode alone it's not display correctly and change to it: &amp;lt;h2&amp;gt;SomeText&amp;lt;/h2&amp;gt;

So When I am using @Html.Raw alone it's not display correctly and chage to it: &lt;h2&gt;SomeText&lt;/h2&gt;

Now:

I can't understand why did not work alone when I am using @Html.Raw or @WebUtility.HtmlDecode? but when I am using First @WebUtility.HtmlDecode and next @Html.Raw together it's work correctly like it. @Html.Raw(WebUtility.HtmlDecode(@Item.Content))

&lt;h2&gt;SomeText&lt;/h2&gt; Stored in @Item.Content

2
  • do you use submit button to save ckeditor value? Commented Jun 7, 2014 at 11:46
  • @AshkanMobayenKhiabani Yes. Commented Jun 7, 2014 at 12:22

2 Answers 2

1

Simply use

@Html.Raw("&lt;h2&gt;SomeText&lt;/h2&gt;")

this will decode the encoded data to html and will store it in DB u r trying to decode and thn u r again encoding it thats the reason u getting the html encode data in DB

Sign up to request clarification or add additional context in comments.

7 Comments

I was written in question. when I am using HtmlDecode (webutility or httputility also @html.raw) alone it's not display correctly.
you say Raw avoid Html Encoding but in this video using "Raw" and display correctly.
ya, html raw avoid encoded code and it will convert tht code in to normal html tags and values Html.Raw(WebUtility.HtmlDecode("&lt;h2&gt;SomeText&lt;/h2&gt;")) Return Some Text in Bold Format #tried
I don't understand difference of "&lt;h2&gt;SomeText&lt;/h2&gt;" and "&amp;lt;h2&amp;gt;SomeText&amp;lt;/h2&amp;gt;"
&lt;h2&gt;SomeText&lt;/h2&gt is a html.encoded value And &amp;lt;h2&amp;gt;SomeText&amp;lt;/h2&amp;gt; is browser encoded value , this is how browser reads the data
|
1

if you are using submit button:

<input type="submit" value="save html" onclick="saveIt()" />

do like this:

function saveIt(){
     $('.editor').val(encodeURIComponent($('.editor').val()));
}

or If you just saving its value by ajax you then you can post encodeURIComponent of the html instead of html itself.

now WebUtility.HtmlDecode should work perfectly.

3 Comments

The question was written incorrectly. Questions were modified
Dear Ashkan I was saved html by ckeditor in webform version normallty and display with mvc version
I don't encoding html. I think ckeditor encoding html when send to code behind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.