-1

アップロードするためにカスタムエラーメッセージを渡すにはどうすればよいですか?

コントローラのアクションで例外が発生した場合(try / catchでキャッチ)-uploadifyスクリプトに渡すにはどうすればよいですか?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);
                },
4

1 に答える 1

1

編集

この投稿は、uploadify で JSON を使用して解決するのに役立ちます。JSON.parse を機能させるには、このファイルまたは同等のファイルを含める必要があります。

このようなものが機能するはずです-JSONを有利に使用してください

 [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;
                 },
于 2012-04-17T22:39:25.877 に答える