TinyMCE with Ajax Form in ASP.NET MVC

I installed the form using TinyMCE on my MVC website. For this, I have ajaxForm in partial form:

        <% using (Ajax.BeginForm(
                   (Model.ViewMode == ViewMode.Insert) ? "Create" : "Edit",
                   new AjaxOptions()
                   {
                       UpdateTargetId = CustomerViewModel.WindowContentContainerId,
                       OnFailure = "addValidation"
                       //OnSuccess = "refresh"
                   }))
               {%>

    bla bla

     <p>
                <label for="CustomerBaneer">
                    Baner:</label>
                <%= Html.TextArea(CustomerViewModel.FieldPrefix + "CustomerBaneer", Model.CustomerToEdit.CustomerBaneer)%>
                <%= Html.ValidationMessage(CustomerViewModel.FieldPrefix + "CustomerBaneer", "*")%>
     </p>
<input type="submit" value="Save" class="save" />
    <%}%>

    <script type="text/javascript">
     tinyMCE.init({
                mode : "textareas"
                });
            }
    </script>

The tinyMce component looks good, and I can change my text to bold, underline, etc. However, when I click on save, the request is sent with the textarea content without formatting it (I tracked it with firebug), why? Is there any default HTML descriptor deletion function using ajax form?

Thanks.

+3
source share
2 answers

U need to save the text from tinymce to this textArea before sending. The OnBegin function is too late, so I did it like this:

function tinyToText() {

                ed = tinyMCE.getInstanceById('yourId');

                if (ed) {
                    $("#yourId").val(ed.getContent());
                }
            }

<input type="submit" value="Send" onclick="tinyToText();" />
+4
source

, OnBegin AjaxOptions, tinyMCE.triggerSave() . jQuery, , , Ajax.BeginForm.

new AjaxOptions()
{
    UpdateTargetId = CustomerViewModel.WindowContentContainerId,
    OnFailure = "addValidation",
    OnBegin = "preSubmit"
    //OnSuccess = "refresh"
}

<script="text/javascript">
  function preSubmit() {
    tinyMCE.triggerSave();
  }
</script>
+2

Source: https://habr.com/ru/post/1720327/


All Articles