2012-10-15 56 views
0

大家好寫的圖像優化內容的代碼時,顯示我需要做的這個任何機構PLZ錯誤幫助我,我在mvc4努力解決這一IAM收到此錯誤如何在mvc4中創建ImageOptimize(出錯)?

這裏是我的代碼:控制器

public ActionResult Uploading(ImageModel model) 
     { 
      var uploadFolder = HostingEnvironment.MapPath("~/App_Data"); 
      uploadFolder = Path.Combine(uploadFolder, DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss/fff")); 
      Directory.CreateDirectory(uploadFolder); 
      var streamProvider = new PreserveFilenameMultipartFileStreamProvider(uploadFolder); 

      Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => 
      { 
       foreach (var uploadedFile in Directory.GetFiles(uploadFolder)) 
       { 

        var medium = Path.Combine(uploadFolder, "medium-" + Path.GetFileName(uploadedFile)); 
        var thumbnail = Path.Combine(uploadFolder, "thumb-" + Path.GetFileName(uploadedFile)); 
        ImageTools.Resize(uploadedFile, thumbnail, 100, 100); 
        ImageTools.Resize(uploadedFile, medium, 50, 50); 
       } 
       return new HttpResponseMessage() 
       { 
        Content = new StringContent("File uploaded.") 

       }; 

      }); 
      return View("Upload", model); 

     } 

,這裏是我的索引頁:

@using (Html.BeginForm("Uploading", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    <input type="file" name="ImageUploaded" id="btnUpload" multiple="multiple" accept="image/*" /> 
<button type="submit" id="Upload">Upload</button> 
    <br /> 
    //@Html.DisplayForModel(@ViewData["Time"]);   
    <label>@ViewData["Time"]</label> 

} 

這裏IAM的內容得到一個錯誤:HTTPRequestBase多年平均值包含defnation內容

 Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => 

可以任何機構幫我解決這個問題由於事先

回答

-1

請使用視圖中的以下行:

@using (Html.BeginForm("Action Name", "Controller Name", FormMethod.Post, new { enctype = "multipart/form-data" })) 

因爲您要上傳的文件,你需要定義上面的代碼行。