2016-08-23 74 views
0

所以我試圖讓pluploader v2.1.9爲MVC 4或5工作,我必須完全忽略它背後的想法,因爲我無法找到一個教程或真正的任何細節它。我搜索了這個網站並沒有找到真正的答案。MVC 4/5 pluploader v2.1.9

我試圖讓UI部件的工作,所以我也跟着網站here上的指示,並從UI Widget輸入的代碼這讓我讀出一句話:

你的瀏覽器不有Flash,Silverlight或HTML5支持。

也許我只是太新了MVC或錯過了一個關鍵項目在這裏。任何幫助將不勝感激。

在此先感謝。

+0

所以我得到了一個沒有解釋爲什麼的投票... – whisk

回答

0

檢查這個例子:MVC4 ASP.Net Example

+0

這幫助讓我開始,我能夠弄清楚如何實現用戶界面小部件。謝謝! – whisk

2

的關鍵觀點是連接所有的外部文件,並做正確 觀

@{ 
Layout = null; 
} 

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
<title>UI Widget</title> 
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" /> 
<link rel="stylesheet" href="Scripts/js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" /> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> 
<!-- production --> 
<script type="text/javascript" src="Scripts/js/plupload.full.min.js"></script> 
    <script type="text/javascript" src="Scripts/js/jquery.ui.plupload /jquery.ui.plupload.js"></script> 

</head> 
<body style="font: 13px Verdana; background: #eee; color: #333"> 

<form id="form" method="post" action=""> 
    <div id="uploader"> 
     <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p> 
    </div> 
    <br /> 
</form> 
<script type="text/javascript"> 
    // Initialize the widget when the DOM is ready 
    $(function() { 
     $("#uploader").plupload({ 
      // General settings 
      runtimes: 'html5,flash,silverlight,html4', 
      //url: 'Scripts/upload.php', 
      url: 'Home/Upload', 
      // User can upload no more then 20 files in one go (sets multiple_queues to false) 
      max_file_count: 20, 

      chunk_size: '1mb', 

      // Resize images on clientside if we can 
      resize: { 
       width: 200, 
       height: 200, 
       quality: 90, 
       crop: true // crop to exact dimensions 
      }, 

      filters: { 
       // Maximum file size 
       max_file_size: '1000mb', 
       // Specify what files to browse for 
       mime_types: [ 
        { title: "Image files", extensions: "jpg,gif,png" }, 
        { title: "Zip files", extensions: "zip" } 
       ] 
      }, 

      // Rename files by clicking on their titles 
      rename: true, 

      // Sort files 
      sortable: true, 

      // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that) 
      dragdrop: true, 

      // Views to activate 
      views: { 
       list: true, 
       thumbs: true, // Show thumbs 
       active: 'thumbs' 
      }, 

      // Flash settings 
      flash_swf_url: 'Scripts/js/Moxie.swf', 

      // Silverlight settings 
      silverlight_xap_url: 'Scripts/js/Moxie.xap' 
     }); 


     // Handle the case when form was submitted before uploading has finished 
     $('#form').submit(function (e) { 
      // Files in queue upload them first 
      if ($('#uploader').plupload('getFiles').length > 0) { 

       // When all files are uploaded submit form 
       $('#uploader').on('complete', function() { 
        $('#form')[0].submit(); 
       }); 

       $('#uploader').plupload('start'); 
      } else { 
       alert("You must have at least one file in the queue."); 
      } 
      return false; // Keep the form from submitting 
     }); 
    }); 
</script> 

再有就是控制器,這是我從上面提供的Link獲得的。

的HomeController

using System; 
using System.Web.Mvc; 

namespace PluploadMVC4Demo.Controllers 
{ 
    public class HomeController : Controller 
{ 

    public ActionResult Index() 
    { 
     return View(); 
    } 

    public ActionResult Upload() 
    { 
     for (int i = 0; i < Request.Files.Count; i++) 
     { 
      var file = Request.Files[i]; 
      file.SaveAs(AppDomain.CurrentDomain.BaseDirectory + "Uploads/" + file.FileName); 
     } 
     return Json(new { success = true }, JsonRequestBehavior.AllowGet); 
    } 

} 

}

你需要一個文件夾,名爲上傳添加到根目錄來存儲文件。 所以你的文件結構應該看起來像這樣。現在

enter image description here

唯一的問題是如何保持正被來自擺脫與任何現有的同名文件上傳當前文件。