43

I tried :

string decodedHtml = HttpUtility.HtmlDecode(html);

Where html is the encoded html. It seems that this does not alter the string at all. The html is still encoded.

Liam
  • 27,717
  • 28
  • 128
  • 190
Nick
  • 19,198
  • 51
  • 185
  • 312
  • Please show an example of the string – Pekka May 16 '11 at 20:18
  • 2
    HtmlDecode only decode the values that were encoded using HtmlEncode. FYI there are differences amongst: HtmlEncode vs. UrlEncode vs. Uri.EscapDataString. Some useful info is here : http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx – Dio Phung May 14 '14 at 07:19
  • Note that Asp.Net/Mvc actions normally convert url query params encoded this way (encodeURIComponent) into plain strings automatically: If your action method requires "paramName", it tries looking for that value as a query parameter (it also checks form-post parameters). This is called "parameter binding". It also converts more complex types eg bool, int, float. – Curtis Yallop Oct 24 '14 at 21:27

3 Answers3

79
string s = System.Uri.UnescapeDataString(html);
Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
3

Think you can use this code.

HttpContext.Current.Server.UrlDecode(html)
Binh LE
  • 387
  • 5
  • 17
0

`

<p>Click the button to encode a URI.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var uri = "https://informerspro.com";
  var res = encodeURIComponent(uri);
  document.getElementById("demo").innerHTML = res;
}
</script>

`

  • 1
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Tyler2P Aug 13 '21 at 12:06