【发布时间】:2026-01-03 16:05:02
【问题描述】:
我们的内部网站上有一个页面在一些地方使用了 TinyMCE 的 RichText 编辑器。其中一个地方是当用户单击按钮时弹出的局部视图。这是唯一出现此错误的地方。当用户尝试使用工具栏图标或菜单 -> 插入 -> 图片插入图片时,会发生此错误。文件选择器窗口正常显示,在您选择文件(从您的 PC)之后,此错误出现在浏览器的控制台窗口中。
代码如下:
<head>
<script>
tinymce.init({
selector: '.BtCEditor',
plugins: 'powerpaste lists image link searchreplace emoticons',
toolbar: 'powerpaste | image imagetools undo redo | styleselect | bold italic charmap | alignleft aligncenter alignright alignjustify link | lists numlist outdent indent | emoticons ',
powerpaste_block_drop: false,
powerpaste_allow_local_images: true,
automatic_uploads: true,
file_picker_types: 'image',
file_picker_callback: function (cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function () {
var id = 'blobid' + (new Date()).getTime();
var blobCache = tinymce.activeEditor.editorUpload.blobCache; /* tinymce.activeEditor.editorUpload <-- this is coming up NULL */
var base64 = reader.result.split(',')[1];
var blobInfo = blobCache.create(id, file, base64);
blobCache.add(blobInfo);
/* call the callback and populate the Title field with the file name */
cb(blobInfo.blobUri(), { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
}
});
</script>
</head>
....
AND
<div class="editor-field">
@Html.TextBoxFor(x => x.Description, new {@class = "BtCEditor"})
@Html.ValidationMessageFor(x => x.Description)
</div>
我能想到的唯一原因是在用户单击显示 PartialView 的按钮之前,页面上也使用了 TinyMCE JS。所以基本上它被使用了两次。也许 tinymce.activeEditor.editorUpload 为 null,因为它已经在使用中?
任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: javascript image null tinymce