Save RichTextEditor content in database (import and export)

Hi,
use getHtml method to get the HTML string from the RTE and pass the value to the controller and save the contents in database table field, but I get this error message:
"A potentially dangerous Request.Form value was detected from the client (comment="<p style="text-align...")."

What I want to do is export the data from RTE to the database and import it into RTE when I need it in the same format.

How can I achieve this ?


$("#saveData").click(function () {
        $.ajax({
            url: '@Url.Action("SaveRTEdata")',
            data: {
'msg': $("#rteMsg").data("ejRTE").getHtml()
},

            type: "POST",
            success: function (result) { },
            error: function (result) { }
        });
    })

Regards,

Anis


3 Replies

KR Keerthana Rajendran Syncfusion Team January 2, 2018 08:46 AM UTC

Hi Anis, 
 
Thank you for contacting Syncfusion support. 
 
We were able to reproduce the issue in our end. This issue occurs due to the detection of HTML elements(<>) and we suggest to disable the page validation in web config as shown below 
 
<httpRuntime targetFramework="4.5" requestValidationMode="2.0" /> 
    <pages validateRequest="false"> 
 
Please set ValidateInput attribute to false in the controller POST method as shown below  
 
[HttpPost,ValidateInput(false)] 
        public ActionResult SaveRTEdata() 
        { 
            var value=Request.Form["msg"]; 
            return View("RichTextEditorFeatures"); 
        } 
 
We have attached a sample for your reference which can be downloaded from the below link 
 
 
Please refer the below given blogs for more details 
 
 
 
Regards, 
Keerthana. 



AN Anis January 3, 2018 09:21 AM UTC

Hi,
thanks, this was helpful, but i still want to know how to import data (html) from the database to RTE.
I use ajax call and ($("#rte").ejRTE({ value: result });) to set data, but it does not work.

Regards,
Anis


PO Prince Oliver Syncfusion Team January 4, 2018 06:49 AM UTC

Hi Anis, 

Thank you for your update. 

We can use the setHtml method in the RTE control to set the new content from the controller into RTE. The setHtml method can accessed via control’s instance. Kindly refer to the following code snippet. 

[View] 
<div> 
    @{Html.EJ().RTE("rteSample").ContentTemplate(@<p> 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
    </p>).ClientSideEvents(e=> e.Create("onCreate")).Render();} 
</div> 
<br /><br /> 
<button id="btn" >Import content from Server</button> 
 
<script> 
    var rteObj; 
    $(function () { 
        $("#btn").on("click", function () { 
            $.ajax({ 
                url: "@Url.Action("GetData", "Home")", 
                type: "GET", 
                contentType: "application/json; charset=utf-8", 
                success: function (e) { 
                    rteObj.setHtml(e); //setting Html content for RTE 
                } 
            }); 
        }); 
    }); 
    function onCreate() { 
        rteObj = this; // accessing control’s instance 
    } 
</script> 

[Controller] 
public ActionResult GetData() 
{ 
    var NewContent = "<p>This is <b>New</b> content from the <i>Controller</i></p>"; 
    return Content(NewContent); 
} 

We have prepared a sample as per your requirement. Please find the sample from the following location: http://www.syncfusion.com/downloads/support/forum/135255/ze/RTEloadContent1278079239 

Regards, 
Prince 


Loader.
Up arrow icon