Search code examples
asp.net-mvcckeditor

how to upload image in ckeditor with asp.net mvc


when i click on upload image in ckeditor toolbar ,open browse file windows and we can select a file to upload,then in visual studio i see the debug on myuploadfile and save file in directory but when return from function ,ckeditor alert file "Cannot upload file: 34.jpg" what is we return from myuploadfile function until ckeditor dont alert me and work OK

this is my script

DecoupledEditor.create("#mtTextarea"), {
        removePlugins: ['FontFamily', 'strikeThrough'],
        //filebrowserUploadUrl 
        ckfinder: {
            uploadUrl: $ServerRoot + $VirtualDirectory + '/File/UploadCK' // <----this is work and send file here
        }
        //language: 'fa'
    })
        .then(editor => {
            const toolbarContainer = document.querySelector("#mtTextarea_toolbar");
            toolbarContainer.appendChild(editor.ui.view.toolbar.element);
        })
        .catch(err => {
            console.error(err);
        });

and this my c# code

public ActionResult UploadCK2(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor,string langCode)
    {
        //save my file successfully on server

        var returnedValue = "????????????????????????????????????" // <--- i want help for this
        return Content(returnedValue);
    }

Solution

  • this response is answer,function must return this jsonResult

    {
    "uploaded": 1,
    "fileName": "foo.jpg",
    "url": "/files/foo.jpg"
    }