0

DropZone JSMVCを使用しています。イメージを保存するActionMethodは、try catchを使用しています。エラーが発生した場合はActionMethodから戻る必要がありますので、フロントエンドがそのことを認識し、すべてが成功したことを示す代わりにエラーマークを表示します。MVCコントローラからエラーが発生した場合、DropZoneがそれを受け取るようにするにはどうすればいいですか

DropZoneで組み込まれていますか、それとも完全なイベントにバインドする必要がありますか?もしそうなら、どうですか?

DropZone JS completeイベント

this.on("complete", function (file, response) { 
     // If an error has occurred, mark the item as failed 
     if (response.code != 200){ 
     } 

     // If it went through successful, show that to the user 
     if (response.code == 200){ 
     } 
    }); 

の例これがうまくいく場合は、MVCに私はちょうどそのような return new HttpStatusCodeResult(HttpStatusCode.BadRequest)return new HttpStatusCodeResult(HttpStatusCode.Ok)としてHttStatusCodeResult

UPDATEDを返すことができます - ActionMethod

[HttpPost] 
    public ActionResult SaveImages() 
    {    
     bool isSavedSuccessfully = true; 
     string fName = ""; 
     try 
     { 
      foreach (string fileName in Request.Files) 
      { 
       HttpPostedFileBase file = Request.Files[fileName]; 

       if (HttpPostedFileBaseExtensions.IsImage(file)) 
       { 
        //Save file content goes here 
        fName = file.FileName; 
        if (file != null && file.ContentLength > 0) 
        { 

         var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\", Server.MapPath(@"\"))); 

         string pathString = Path.Combine(originalDirectory.ToString(), "Temp"); 

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

         bool isExists = Directory.Exists(pathString); 

         if (!isExists) 
          Directory.CreateDirectory(pathString); 

         var path = string.Format("{0}\\{1}", pathString, file.FileName); 
         file.SaveAs(path); 

         _testRepository.EditMainPicture("test", pathString, "imageText", 1); 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      // TODO Add error logging!! 
      isSavedSuccessfully = false; 

      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 

     return new HttpStatusCodeResult(HttpStatusCode.Ok); 
    } 

何らかの理由で何かがels eがこの方法で失敗すると、DropZoneはファイルを取得せず、ファイルが正常にアップロードされたことを示します。私はそれが何がActionMethod

+0

[エラーイベント(http://www.dropzonejs.com/#event-error) 'dropzone.on( "エラー"、関数(ファイル、データをリッスン){...}) '。あなたのMVCアクションコードはどこですか? – Jasen

+0

Jasen、あなたのコメントを回答として追加してください。それはうまくいくが、私は 'success'イベントを追加しなければならなかった。 – Sugafree

答えて

0

以内に失敗した場合は、エラーが発生したerror event

をリッスンする必要がありますエラーを示したいと思います。 errorMessageを2番目のパラメータとして受け取り、エラーがXMLHttpRequestによるものであればxhrオブジェクトを3番目とします。

dropzone.on("error", function(file, errorMesage, xhr) { ... }); 
関連する問題