Summernote回调图像上传已完成,但是Form再次提交了帖子请求文件

时间:2019-04-11 09:27:43

标签: asp.net asp.net-mvc summernote

当我在summernote中更新文件图像时,我使用回叫更新图像。没关系。 但是我提交表单,文件在请求中再次发送,我想提交表单而不是再次发送文件。

    $('.textarea-editor').summernote({
        height: 300, // set editor height
        minHeight: null, // set minimum height of editor
        maxHeight: null, // set maximum height of editor
        focus: true, // set focus to editable area after initializing summernote
        callbacks: {
            onImageUpload: function (files, editor, welEditable) {
                sendFile(files[0], editor, welEditable);
            }
        }
    });
    function sendFile(file, editor, welEditable) {
        data = new FormData();
        data.append("file", file);
        $.ajax({
            data: data,
            type: "POST",
            url: "/Image/Upload",
            cache: false,
            contentType: false,
            processData: false,
            success: function (url) {
                $('.textarea-editor').summernote('editor.insertImage', url);
                //editor.insertImage(welEditable, url);
            }
        });
    }

2 个答案:

答案 0 :(得分:0)

请尝试以下解决方案:

    // onImageUpload callback
$('.textarea-editor').summernote({
  callbacks: {
    onImageUpload: function(files) {
      // upload image to server and create imgNode...
      $summernote.summernote('insertNode', imgNode);
    }
  }
});

// summernote.image.upload
$('.textarea-editor').on('summernote.image.upload', function(we, files) {
 data = new FormData();
        data.append("file", files);
        $.ajax({
            data: data,
            type: "POST",
            url: "/Image/Upload",
            cache: false,
            contentType: false,
            processData: false,
            success: function (url) {
               $summernote.summernote('insertNode', url);
            }
        });

});

文档:https://summernote.org/deep-dive/#onimageupload

答案 1 :(得分:0)

从您的表单标签中删除enctype =“ multipart / form-data”