Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
HTML Editor Content is encoded
posted

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]

        [ActionName("email-template")]

        public ActionResult EmailTemplate(EmailTemplate emailTemplate)

        {

            //save template

            return View("email-template", emailTemplate);

        }

 

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'

            }

        }

    }

}

Parents
  • 8421
    posted

    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.

Reply Children