Reputation: 1291
I have an asp.net mvc application and i want to submit an html code on post, i have a custom binder for this request, i have this html code that i submit in a editor
<div id="content-home-rect">
<div class="rect-home"></div>
<div class="rect-home"></div>
<div class="rect-home"></div>
<div class="rect-home"></div>
</div>
when i submit i got this
%3Cdiv%3E%26lt%3Bdiv%20id%3D%22content-home-rect%22%26gt%3B%3C%2Fdiv%3E%3Cdiv%3E%26nbsp%3B%20%26nbsp%3B%20%26lt%3Bdiv%20class%3D%22rect-home%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3C%2Fdiv%3E%3Cdiv%3E%26nbsp%3B%20%26nbsp%3B%20%26lt%3Bdiv%20class%3D%22rect-home%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3C%2Fdiv%3E%3Cdiv%3E%26nbsp%3B%20%26nbsp%3B%20%26lt%3Bdiv%20class%3D%22rect-home%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3C%2Fdiv%3E%3Cdiv%3E%26nbsp%3B%20%26nbsp%3B%20%26lt%3Bdiv%20class%3D%22rect-home%22%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3C%2Fdiv%3E%3Cdiv%3E%26lt%3B%2Fdiv%26gt%3B%3C%2Fdiv%3E
this is my custom binder
var req = controllerContext.HttpContext.Request.Unvalidated.Form;
var model = new ContenutiDetailModel();
foreach (var item in lingue)
{
string html = req.Get("text-" + item);
html = System.Web.HttpContext.Current.Server.HtmlDecode(html);
var ol = new ObjectLingue();
ol.content = html;
ol.lingua = item;
ol.id = req.Get("id-" + item);
model.html.Add(ol);
}
return model;
the html decode give me back always the same string, i don't get why.
Upvotes: 0
Views: 443
Reputation: 31248
The string you've provided appears to have been both HTML-encoded and URL-encoded. You will need to reverse both encoding operations to get the original string back.
It also appears to have extra <div>
tags inserted. You will need to look at how the value is being posted to find out why.
NB: You don't need to go through System.Web.HttpContext.Current.Server
to get to the HtmlDecode
function; it's available on the static HttpUtility
class.
string html = req.Get("text-" + item);
// %3Cdiv%3E%26lt%3Bdiv%20id%3D%22content-home-rect%22%26gt...
html = HttpUtility.UrlDecode(html);
// <div><div id="content-home-rect"></div>...
html = HttpUtility.HtmlDecode(html);
// <div><div id="content-home-rect"></div>...
Upvotes: 1