我目前正在按照说明从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
一些例子说可行,但我的代码在功能上不起作用!
有任何想法吗 ?