0

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.

1 Answer 1

1

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>&lt;div id="content-home-rect"&gt;</div>...

html = HttpUtility.HtmlDecode(html);
// <div><div id="content-home-rect"></div>...
Sign up to request clarification or add additional context in comments.

Comments

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.