热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ajax带文件域上传多文件上传,MVCAjax带参数上传上传多个文件

JavaScript:全局参数:全局定义上传的文件列表varuploadfiles[];其他按钮事件添加文件列表uploadfiles.push({timestam

Javascript:

全局参数:

//全局定义上传的文件列表

var uploadfiles = [];

//其他按钮事件添加文件列表

uploadfiles.push({ "timestamp": timestamp,"data":blob,"paperType":paperType });

上传按钮事件:

var filesnum = uploadfiles.length;

var formData = new FormData();

//上传文件信息

for (var j = 0; j

formData.append(uploadfiles[j].paperType, uploadfiles[j].data);

}

//添加其他

formData.append("paperTitle", "testtesttest");

formData.append("paperAuthor", "author1,author2");

$.ajax({

type: 'POST',

url: '/Home/SciPaperSave',

data: formData,

dataType: 'json',

contentType: false,

processData: false,

success: function (response) {

},

error: function (error) {

}

});

Controller:

Function SciPaperSave() As JsonResult

Dim rootPath = Server.MapPath("/UploadFiles/" + CStr(Now.Year) + "/teacherID")

''''''''获取formdata里面的文件列表

Dim loop1 As Integer

Dim arr1() As String

Dim Files As HttpFileCollection

Files = System.Web.HttpContext.Current.Request.Files

arr1 = Files.AllKeys

For loop1 = 0 To arr1.GetUpperBound(0)

Dim myFile = New HttpPostedFileWrapper(Files(loop1))

myFunctions.myUploadFile(rootPath, myFile)

Dim fileType = arr1(loop1)

Next

''''''''获取formdata里面非文件列表

Dim paperParmeters As NameValueCollection = System.Web.HttpContext.Current.Request.Form

Dim arr2() As String = paperParmeters.AllKeys

For loop1 = 0 To arr2.GetUpperBound(0)

'do something

Next

Threading.Thread.Sleep(5000)

Return Json(New With {.statusCode = 200, .status = "Bad Request! Upload Failed", .file = String.Empty}, JsonRequestBehavior.AllowGet)

End Function



推荐阅读
author-avatar
月芽2502915393
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有