Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Cargue varios archivos con la llamada Ajax [xhr] y envíe una variable adicional

Logré enviar varios documentos a mi controlador usando la siguiente llamada ajax:

 var fileData = new FormData(); for (var i = 0; i < files.length; i++) { fileData.append("UploadDocumentsInput", files[i]); } $.ajax({ type: "POST", url: "/LegalEntity/UploadFiles", async: false, dataType: "json", contentType: false, // Not to set any content header processData: true, // Not to process data data: fileData, success: function (result, status, xhr) { }, error: function (xhr, status, error) { documentSuccess = false; } });

y en el controlador, los recibo de esta manera:

 [HttpPost] public JsonResult UploadFiles() { var listOfDocs = new List<UploadedFile>(); HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; var inputStream = file.InputStream; var inputStreamLength = Convert.ToInt32(inputStream.Length); byte[] streamArray = new byte[inputStreamLength]; var strRead = inputStream.Read(streamArray, 0, inputStreamLength); var docObject = new UploadedFile() { Attachment = streamArray, FileName = file.FileName, }; listOfDocs.Add(docObject); } _personService.SaveDocs(listOfDocs); return Json(files.Count + " Files Uploaded!"); }

Pero también, necesitaré enviar desde mi vista una identificación. Intenté incluirlo en el campo data: y recibirlo como argumento en mi método, pero esto no parece estar funcionando.

Toda ayuda será muy apreciada.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!