HTML Editor Content is encoded
I follow your online sample on how to save content of the igHtmlEditor (http://help.infragistics.com/Help/Doc/jQuery/2013.2/CLR4.0/html/igHtmlEditor_Saving_HTML_Content.html#mvc_define_model).
Once the content get to the controller, the content is encoded e.g. %3Cp%3EEmail%20Template%3C/p%3E, and gets saved to SQL table in encoded format.
Once re-loaded, the igHtmlEditor displays it as encoded format. I was expecting to see content to be displayed as Email Template
Please advise, how to fix this problem.
Model
public class EmailTemplate
{
public int Id { get; set; }
[AllowHtml]
public string BodyText { get; set; }
}
Controller
[ActionName("email-template")]
public ActionResult EmailTemplate(int id = 0)
EmailTemplate emailTemplate = DataRepositories.GetEmailTemplate(id);
return View("email-template", emailTemplate);
[HttpPost]
public ActionResult EmailTemplate(EmailTemplate emailTemplate)
//save template
View
@using (Html.BeginForm("email-template", "Email", FormMethod.Post, new { id = "frmEmailTemplate" }))
@Html.HiddenFor(m => m.Id)
@(Html.Infragistics().
HtmlEditorFor(m => m.BodyText).
ID("htmlEditor").
Render()
)
JavaScript
$(function () {
var height = $('html').hasClass('touch') ? 500 : 350;
// initialize igHtmlEditor
var htmlEditor = $("#htmlEditor").igHtmlEditor({
width: "99%",
height: height,
inputName: "BodyText",
showCopyPasteToolbar: false,
customToolbars: [
name: "customToolbarSave",
collapseButtonIcon: "ui-igbutton-collapse",
expandButtonIcon: "ui-igbutton-expand",
items: [setToolbar("saveTemplate", saveTemplet, "Save Template")
]
}]
});
function saveTemplet(ui) {
var data = $("#frmEmailTemplate").serialize();
$.ajax({
type: "POST",
url: "/Email/email-template",
data: data,
dataType: "text"
function setToolbar(name, handler, value) {
return {
name: name,
type: "button",
handler: handler,
scope: this,
props: {
isImage: {
value: false,
action: '_isSelectedAction'
},
imageButtonTooltip: {
value: value,
action: '_tooltipAction'
imageButtonIcon: {
value: "ui-icon-contact",
action: '_buttonIconAction'
The content of the editor is encoded when sending to the server as the content of the editor is made up of HTML tags which need to be encoded to transmit properly. What you can do to get the non-encoded markup is call HttpUtility.UrlDecode(value) which would return the markup as you expect.
Please let me know if this meets your requirements or let me know if I may be of any other help.
Thanks Jason
I have tried to use the HttpUtility.UrlDecode, but unfortunately I get the content displayed as <p>Hello World</p>.
What am I missing?
This is my view code
@{
Model.BodyText = HttpUtility.UrlDecode("%3Cp%3EHello%20World%3C/p%3E"); ;
using (Html.BeginForm("email-template", "Email", FormMethod.Post, new { id = "frmOutputTemplate" }))
My script code;