2012-07-20 91 views

回答

2

托尼,

直接从我的工作,现在AB MVC3应用摘自:

<script type="text/javascript"> 
    function initupLoadify() { 
     $("#fileInput").uploadify({ 
      uploader: '@Url.Content("~/scripts/swf/uploadify.swf")', 
      script: '@Url.Action("Upload", "Home")', 
      cancelImg: '@Url.Content("~/Content/cancel.png")', 
      auto: true, 
      sizeLimit: 5500000, 
      fileDataName: 'fileData', 
      //scriptData: { 'propertyId': $("#PropertyID").val() }, 
      buttonText: 'Add Schedule', 
      wmode: 'transparent', 
      //buttonImg: '@Url.Content("~/Content/button.png")', // make nice gradient image for button 
      onComplete: function (event, queueId, fileObj, response) { 
       $("#msg").html(response); 
       // do something 
       setTimeout(2000, window.location = '@Url.Action("Index")' + '?id=' + response); 
       return true; 
      }, 
      onCancel: function (evt, queueId, fileObj, data) { 
       $("#msg").html("<br />Operation cancelled"); 
       return true; 
      }, 
      onOpen: function (evt, queueId, fileObj) { 
       $("#msg").html("<br />Upload in progress"); 
       return true; 
      }, 
      onError: function (event, queueId, fileObj, errorObj) { 
       $("#msg").html(fileObj.name + " was not uploaded "); 
       if (errorObj.status == 404) 
        $("#msg").html("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>"); 
       else if (errorObj.type === "HTTP") 
        $("#msg").html("error " + errorObj.type + ": " + errorObj.status); 
       else if (errorObj.type === "File Size") 
        $("#msg").html(fileObj.name + " " + errorObj.type + " Limit: " + errorObj.info/1000 + " KB"); 
       else 
        $("#msg").html("error " + errorObj.type + ": " + errorObj.text); 
      } 
     }); 
    }; 
</script> 

希望这有助于

+0

我见过类似的代码,但它只显示文件的数据。但是如果我想要显示消息在服务器上发生了什么? – Tony 2012-07-20 11:03:50

+0

另外,'errorObj.text'返回undefined – Tony 2012-07-20 11:05:15

+1

tony - 我明白你说的话(控制器/服务层代码,tho没有意识到这个问题)。我还没有处理这个问题,但是你现在有了我的'研究'头脑,所以会有一个挖掘 – 2012-07-20 11:07:02

0

这里是一个MVC 3 example

如果您使用的版本是3.0+,使用onUploadComplete而不是onComplete(实现它们的参数不同)。

相关问题