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
我有一个asp.net mvc应用程序,我想在帖子上提交一个HTML代码,我有一个自定义的绑定器,我有这个html代码,我在编辑器中提交
<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.
html解码给我回来总是相同的字符串,我不明白为什么。
1 个解决方案
#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.
您提供的字符串似乎是HTML编码和URL编码。您将需要反转两个编码操作以获取原始字符串。
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.
注意:您不需要通过System.Web.HttpContext.Current.Server来获取HtmlDecode函数;它可以在静态HttpUtility类上使用。
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>...
#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.
您提供的字符串似乎是HTML编码和URL编码。您将需要反转两个编码操作以获取原始字符串。
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.
注意:您不需要通过System.Web.HttpContext.Current.Server来获取HtmlDecode函数;它可以在静态HttpUtility类上使用。
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>...