小编hid*_*ran的帖子

Summernote上传文件到服务器

我目前正在按照说明从ASP.NET MVC Razor中的summernote控件处理图像上传.

服务器代码:

[HttpPost]
    public ActionResult UploadImage(HttpPostedFileBase file)
    {
        var imageUrl = UpdateProfilePicture(file);
        return Json(imageUrl);
    }
Run Code Online (Sandbox Code Playgroud)

客户端ajax:

<script>
$('.summernote').summernote({
    height: 200,
    focus: true, onImageUpload: function (files, editor, welEditable) {
        sendFile(files[0], editor, welEditable);
    }
});
function sendFile(file, editor, welEditable) {

    console.log(file);
    $.ajax({
        data: {file:file},
        type: "POST",
        url: "@Url.Action("UploadImage","Message")",
        cache: false,
        contentType: false,
        processData: false,
        success: function (url) {
            editor.insertImage(welEditable, url);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我在服务器端方法得到了一个结果,但参数HttpPostedFileBase file为null

一些例子说可行,但我的代码在功能上不起作用!

有任何想法吗 ?

asp.net asp.net-mvc summernote

5
推荐指数
1
解决办法
2401
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

summernote ×1