我使用jQuery / Ajax将图像上传到服务器像这样:
JS:
var formdata = new FormData();
for (i = 0; i < fileInput.files.length; i++) {
//Appending each file to FormData object
formdata.append(fileInput.files[i].name, fileInput.files[i]);
}
//This is where I want to send additional data
formdata.append('id', $('#txtTest').val());
ASP MVC控制器:
public JsonResult FileUpload()
{
********* //How Can get id here ? **********
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
int fileSize = file.ContentLength;
string fileName = new DateTime().GetTimestamp(DateTime.Now) + "," + file.FileName;
System.IO.Stream fileContent = file.InputStream;
file.SaveAs(Server.MapPath("~/UploadImages") + fileName);
}
return Json(new { message = Request.Files.Count});
}
如何在Controller中获取附加属性?