Patryk Imosa
Patryk Imosa

Reputation: 824

Decoding url encoded with encodedURI in javascript to C#

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?

Upvotes: 0

Views: 1184

Answers (2)

Barr J
Barr J

Reputation: 10927

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

Upvotes: 0

Sky Fang
Sky Fang

Reputation: 1101

  1. You need to use HttpUtility.HtmlDecode,not HttpUtility.UrlDecode
  2. Maybe you also need to use @Html.Raw() to show your content

Upvotes: 1

Related Questions