HTML
First implement the function below, to create an element and get your html
function HtmlEncode(s)
{
var el = document.createElement("div");
el.innerText = el.textContent = s;
s = el.innerHTML;
el.remove();
return s;
}
Then in your POST you encode the string and send
var conteudo=HtmlEncode($("#MinhaTextArea").val())
$.ajax({
url: '/Meucontrole/MinhaAction',
method:"Post",
data:{parametro:conteudo},
success: function (d) {
//TODO:;
}
})
Controller
In your controler you will receive the string encoded in the parametro
parameter, to decode use System.Web.HttpUtility.HtmlDecode()
and to code again
System.Web.HttpUtility.HtmlEncode(t)
.
[HttpPost]
public ActionResult MinhaAction(string parametro)
{
var decodificado = System.Web.HttpUtility.HtmlDecode(parametro);
//TODO:;
var codificado = System.Web.HttpUtility.HtmlEncode(decodificado);
return View();
}