ASP MVC获取使用Jquery / Ajax文件上载发送的其他数据

时间:2017-02-14 12:07:25

标签: jquery asp.net ajax asp.net-mvc

我使用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中获取附加属性?

0 个答案:

没有答案