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
2165
Posting HTMLEditor Data to MVC controller
posted

I want to save in the database the value of a igHtmlEditor. I am using Ajax to post form data like this:

$.ajax({
     url: '@Url.Action("Save","MyData")',
     type: "POST",
     data: $("#MyForm").serialize(),
     success: function (data) {
       cheer(data);
       }
});

That works fine but I have a problem with igHTMLEditor, when I type 'AA + BB' (without apostrophe and in bold) its corresponding HTML is:

<span style="font-weight: bold;">AA + BB</span>

That is serialized with jQuery using standard URL-encoded notation and sent to the controller, the string is:

%3Cspan%20style=%22font-weight:%20bold;%22%3EAA%20+%20BB%3C/span%3E

In the controller I want to deserialize it before save it in the database, so I do something like:

public ActionResult Save(string mystring) {
    SaveToDB(System.Web.HttpUtility.UrlDecode(mystring));
}

But UrlDecode replace '+' with an space resulting in:

   AA   BB

Two 'A', three spaces, and two 'B'.

How to send igHtmlEditor values to database using Ajax and MVC and then back to client without losing any information due to serialization issues?

Parents
No Data
Reply
  • 8421
    posted

    Hello Luis,

    Which version of jQuery are you using and how do you have your view set up? From what I'm seeing, serialize should convert the string with the + being converted to %2B. For example, please see the following jsFiddle I put together to research this behavior:

    http://jsfiddle.net/azrxf3zv/

Children