c# – Blueimp多文件上传器与ASP.NET MVC 3

我正在尝试添加 blueimp File Upload一个MVC应用程序,我有问题在接收文件的后期操作(即将进行多文件上传功能).有人可以帮我看出来吗?

在我看来,我有以下代码

<form id="file_upload" enctype="multipart/form-data" action="Home/SaveFile" method="post">    
   <input type="file" name="file" multiple="true"/>
   <button>Upload</button>
   <div>Upload files</div>        
</form>
<br />
###############################
<table id="files">
</table>

<button id="start_uploads">Start uploads</button>
<button id="cancel_uploads">Cancel uploads</button>

blueimp文件上传的JQuery代码如下:

$(document).ready(function () {

        $('#file_upload').fileUploadUI({
            uploadTable: $('#files'),downloadTable: $('#files'),buildUploadRow: function (files,index) {
                return $('<tr><td class="file_upload_preview"><\/td>' +
                        '<td>' + files[index].name + '<\/td>' +
                        '<td class="file_upload_progress"><div><\/div><\/td>' +
                        '<td class="file_upload_start">' +
                        '<button class="ui-state-default ui-corner-all" title="Start Upload">' +
                        '<span class="ui-icon ui-icon-circle-arrow-e">Start Upload<\/span>' +
                        '<\/button><\/td>' +
                        '<td class="file_upload_cancel">' +
                        '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                        '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                        '<\/button><\/td><\/tr>');
            },buildDownloadRow: function (file) {
                return $('<tr><td>' + file.name + '<\/td><\/tr>');
            },beforeSend: function (event,files,index,xhr,handler,callBack) {
                handler.uploadRow.find('.file_upload_start button').click(callBack);
            }
        });
        $('#start_uploads').click(function () {
            $('.file_upload_start button').click();
        });
        $('#cancel_uploads').click(function () {
            $('.file_upload_cancel button').click();
        });
    });

并在控制器内部采取以下动作方式:

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SaveFile(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (HttpPostedFileBase file in files)
        {
            //some file upload magic                
        }
        return View("MyView");
    }

我正在使用MVC 3.

在action方法中,如果参数类型为IEnumerable,则它将接收null,如果参数的类型为HttpPostedFileBase,则以奇怪的方式接收文件,并且action方法无法正常运行.

非常感谢任何一种帮助,谢谢.

干杯!

解决方法

将为每个文件调用SaveFile控制器操作.所以应该是这样的:
[HttpPost]
public ActionResult SaveFile(HttpPostedFileBase file)
{
    //some file upload magic

    // return JSON
    return Json(new
    {
        name = "picture.jpg",type = "image/jpeg",size = 123456789
    });
}

如果您想在同一个请求中处理多个上传文件,可以查看respective section of the documentation.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...