2015-02-09 24 views
5

Tôi hiện đang làm hướng dẫn sau đây để xử lý tải lên hình ảnh từ điều khiển mùa hè trong ASP.NET MVC Razor.Tải tệp Summernote lên máy chủ

đang Server:

[HttpPost] 
    public ActionResult UploadImage(HttpPostedFileBase file) 
    { 
     var imageUrl = UpdateProfilePicture(file); 
     return Json(imageUrl); 
    } 

Khách hàng bên 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); 
     } 
    }); 
} 

tôi có kết quả ở phương pháp phía máy chủ một, nhưng thông số HttpPostedFileBase file là null

một số ví dụ nói rằng hoạt động, nhưng mã của tôi không hoạt động chức năng!

Bất kỳ ý tưởng nào?

+0

Bạn có quản lý để sửa chữa nó? – Stefanvds

+0

Điều gì sẽ xảy ra với giao diện console.log (tệp) của bạn? Tôi nghĩ rằng giá trị đó không thể được dịch chính xác thành HttpPostedFileBase –

Trả lời

0

Trong "Yêu cầu" đối tượng phương pháp sử dụng của bạn để có được file như thế này:

 [HttpPost] 
    public string UploadImage() 
    { 
     for (int i = 0; i < Request.Files.Count; i++) 
     { 
      var file = Request.Files[i]; 

      var fileName = Path.GetFileName(file.FileName); 

      var path = Path.Combine(Server.MapPath("~/Images/"), fileName); 
      file.SaveAs(path); 
     } 
     return YOUR UPLOADED IMAGE URL; 
    } 
Các vấn đề liên quan