0

I'm making simple article adding. I have a CKEditor and I take from this data and encode it with encodeURI in javascript and send it to ViewController then I put it into table in database. Then I want to show the article, so I <% HTML.RenderAction("MyAction); %>" and in this action I decode the url from database using HttpUtility.UrlDecode(content). But it shows for example HTML tags instead of being formatted. It is shown as a text. When in Chrome I click right and show HTML then there are words like :

& lt; p &gt ; Some text here&lt ; / p & g t;

There is no space in between characters I added them because it shows

<p></p>

What can I do to make it working properly?

2 Answers 2

1
  1. You need to use HttpUtility.HtmlDecode,not HttpUtility.UrlDecode
  2. Maybe you also need to use @Html.Raw() to show your content
Sign up to request clarification or add additional context in comments.

1 Comment

I was encoded with URI so decoding with HttpUtility.HtmlDecode doesn't work. But the second point is right. I work in MVC 2 so there isn't @Html.Raw() but I used MVCHtmlString.Create(content) and that's it!
0

Since you are decoding the html and not the url, you need to use HttpUtility.HtmlDecode.

HttpUtility.UrlDecode does not know how to deal with html tags, only with a url format, so trying url decode on html will provide someting like:

& lt; p &gt ; Some text here&lt ; / p & g t;

Which is the string representation of the html, which basically, is proving that what it is doing is actually correct, because it is decoding, just not in the format you need. Cocnlusion is:

HttpUtility.HtmlDecode

1 Comment

But I encoded it with javascript to URI and there is a percentage encoding.

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.