2011-08-23 60 views

回答

0

是一樣的正常的文件上傳,但我喜歡plupload我會用我的項目,所以下面的代碼將與plupload

[HttpPost] 
    public ActionResult Create(FormCollection collection) 
    { 
     // my project need single file upload so i get the first file 
     // also you can write foreach statement to get all files 
     HttpPostedFileBase postedFile = Request.Files[0]; 
     Image image = new Image(); 
     if (TryUpdateModel(image)) 
     { 
      fRepository.AddImage(image); 
      fRepository.Save(); 

      // Try to save file 
      if (postedFile.ContentLength > 0) 
      { 
       string savePath = Path.Combine(Server.MapPath("~/Content/OtelImages/"), image.ImageID.ToString() + 
                Path.GetExtension(postedFile.FileName)); 
       postedFile.SaveAs(savePath); 

       // Path for dbase 
       image.Path = Path.Combine("Content/OtelImages/", image.ImageID.ToString() + 
                Path.GetExtension(postedFile.FileName)); 
      } 

我沒有改變的代碼,但如果您需要任何進一步的幫助請問,我會解釋

+1

嗨c0demaster,感謝您的幫助。我已經閱讀了一些關於這個的帖子,但是我不能讓plupload在我的MVC 2項目中運行。請給我更多的細節。謝謝! – Ryan

+0

嗨瑞安您好,我從舊項目中得到了這個代碼,我認爲它會起作用。但plupload需要ajax交互,所以我會爲plupload編寫代碼,它可能會更有效。所以請讓我知道,如果它的工作或不因爲我出我的桌面comp。我無法嘗試 – c0demaster

+0

嗨c0demaster, 哪些庫或文件需要包含到我的項目?請幫我編碼查看頁面。 – Ryan