2012-04-17 5 views
-1

アップロードするカスタムエラーメッセージをどうやって渡すことができますか?uploadify onError not called

コントローラのアクションで例外が発生した場合(try/catchによってキャッチされます)、アップロードスクリプトにどのように渡しますか? onErrorイベントは呼び出されませんか?

[HttpPost] 
    public ActionResult Upload(HttpPostedFileBase fileData, FormCollection forms) 
    { 
     try 
     {     
     if (fileData.ContentLength > 0) 
     { 
      var statusCode = Helper.UploadList(); 
      if (statusCode.Equals(System.Net.HttpStatusCode.Created)) 
      return Json(new { success = true });      
     }     
     } 
     return Json(new { success = false });   
    } 
    catch (Exception ex) 
    { 
    return Json(new { success = false });  
    } 
} 

    'onComplete': function (event, queueID, fileObj, response, data) { 
        if (response == '{"success":true}') { 
         alert("File uploaded successfully."); 
        } 
        else if (response == '{"success":false}') { 
         alert('File failed to upload. Please try again!');     
        } 
        else { 
         $("#file_uploadDomain").uploadifyCancel(queueID); 
        } 
        return false; 
       }, 

       'onError': function(event, ID, fileObj, errorObj) { 
        alert(errorObj.type + ' Error: ' + errorObj.info); 
       }, 

答えて

1

EDIT

This postあなたはuploadifyでJSONを使用して解決するのに役立つはずです。 JSON.parseが機能するには、this fileまたは同等のものを含める必要があります。このような

何かが動作するはずです - あなたの利点ずっと簡単だったでしょう

[HttpPost] 
    public ActionResult Upload(HttpPostedFileBase fileData, FormCollection forms) 
    { 
     try 
     {     
     if (fileData.ContentLength > 0) 
     { 
      var statusCode = Helper.UploadList(); 
      if (statusCode.Equals(System.Net.HttpStatusCode.Created)) 
      return Json(new { success = true });      
     }     
     } 
     return Json(new { success = false, message = "No file was specified." });   
    } 
    catch (Exception ex) 
    { 
    return Json(new { success = false, message = ex.ToString() });  
    } 
} 

    'onComplete': function (event, queueID, fileObj, response, data) { 
        var json = JSON.parse(response); 
        if (json.success) { 
         alert("File uploaded successfully."); 
        } 
        else if (!json.success) { 
         alert(json.message);     
        } 


    //not sure what else you could have here for the value of success 
//, thus a redundant else statement, but I will leave it in. 
        else { 
         $("#file_uploadDomain").uploadifyCancel(queueID); 
        } 
        return false; 
       }, 
+0

にJSONを使用...しかしresponse.successはonCompleteの中で定義されていません。 – GoldenUser

+0

いいえ、あなたは正しいです... – Tommy

+0

data.successとdata.messageはどちらも定義されていません – GoldenUser