如何获取jquery文件上传以回发[httpPost] index.cshtml()以外的指定操作?

gen*_*eek 1 asp.net-mvc jquery file-upload multifile-uploader asp.net-mvc-3

我正在使用jquery文件上传器(每个blueimp),我想知道如何将回发指向特定的http帖子,而不是index.cshtml(默认情况下会发布到index.cshtml)?

例如,在调用Home/Bulk时...然后在选择文件后,回发默认为[httppost] index.cshtml()...如何将其指向[httppost] bulk.cshtml()?谢谢!

查看(Bulk.cshtml):

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.iframe-transport.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.fileupload.js")" type="text/javascript"></script>


@using (Html.BeginForm("Bulk", "Home"))  // I want this to direct back to httppost:bulk handler
{
<input id="fileupload" type="file" name="files" multiple="multiple"/>
}
Run Code Online (Sandbox Code Playgroud)

控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (var file in files)
        {
            var filename = Path.Combine(Server.MapPath("~/App_Data"), file.FileName);
            file.SaveAs(filename);
        }
        return View();
    }

    public ActionResult Bulk()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Bulk(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (var file in files)
        {
            var filename = Path.Combine(Server.MapPath("~/App_Data"), file.FileName);
            file.SaveAs(filename);
        }
        return View();
    }

}
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 5

您可以url在设置插件时使用该属性来指示您希望它提交的操作:

$('#fileupload').fileupload({
    url: 'home/bulk',
    done: function (e, data) {
    }
});
Run Code Online (Sandbox Code Playgroud)