如何在uploadify之后执行控制器Action?

时间:2011-10-20 17:42:07

标签: c# asp.net-mvc-3 uploadify

我不了解MVC3和Uploadify幕后发生的事情的细节。我需要允许下面的页面上传多个文件。这到目前为止工作。我可以上传文件,它们会保存到服务器上。问题是我需要重新加载页面,其中包含上传文件列表的摘要。这就像是asp.net webforms中的回发。

@model Tangible.Models.UploadViewModel

        <input id="uploadfile" name="uploadfile" type="file" class="uploadify"  />

The template provided outlines the upload headings and format for Disposed Assets, Leased, Loaned, Rented, and Business Assets. 

The files must be uploaded in Microsoft Excel format following the templates provided. Each template must be a separate worksheet within the Excel file being uploaded. Prior to uploading, please review the template in Excel format which requires all headings be located in row one. Do not use commas in numeric fields but the decimal place character “.” is required when indicating cents. If you have any questions or concerns regarding the format please contact our Tangible Personal Property Department at 941.861.8291.

Note: Summary schedule item 21.- Pollution Control Equipment must be accompanied by the current DEP certificate for the reported equipment. (Please include an upload for a DEP Certificate)



        <script type="text/javascript">
            $(document).ready(
            function () {
            @{ var auth = Request.Cookies[FormsAuthentication.FormsCookieName] == null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value;}
                var auth = "@auth";
                var ASPSESSID = "@Session.SessionID";                

                $(".uploadify").uploadify({
                    'uploader': '@Url.Content("~/Scripts/uploadify.swf")',
                    'cancelImg': '@Url.Content("~/Images/cancel.png")',
                    'buttonText': 'Upload',
                    'script': '@Url.Content("~/Wizard/Upload")',
                    'fileDesc': 'Files',
                    'fileExt': '*.*',
                    'auto': true,
                    'scriptData': { ASPSESSID: ASPSESSID, AUTHID: auth}
                });
            }
        );

            </script>

- 控制器操作:在将所有文件上传到回发后需要以某种方式执行最后一步

  [HttpPost]
        public ActionResult Upload(HttpPostedFileBase FileData)
        {
            var saveLocation = Path.Combine(Server.MapPath("\\"), "returns\\" + DR405Profile.CurrentUser.TangiblePropertyId);
            System.IO.Directory.CreateDirectory(saveLocation);
            FileData.SaveAs(Path.Combine(saveLocation, FileData.FileName));
            ViewData["UploadStatus"] = String.Format("File name: {0}, {1}Kb Uploaded Successfully.", FileData.FileName, (int)FileData.ContentLength / 1024);
            return View();
        }

1 个答案:

答案 0 :(得分:1)

您可以订阅客户端上的onAllComplete事件并执行您想要执行的任何操作。例如,您可以重新加载当前网址,发送AJAX请求以仅刷新网址的一部分,...浏览documentation,您可能会发现有趣的选项和要订阅的事件。