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

386
Views
cómo agregar un objeto modelo a formData en AJAX y recuperarlo usando asp.net

Desarrollé un método Ajax POST para pasar los datos al controlador. Primero agrego mi archivo cargado a formData . Luego quiero vincularle un model object . Lo hice. Pero en el controlador, mi modelo siempre es nulo.

Por favor, ayúdenme a agregar correctamente y obtener el modelo y el archivo correctamente. Función de javascript:

 var $file = document.getElementById('file'), $formData = new FormData(); if ($file.files.length > 0) { for (var i = 0; i < $file.files.length; i++) { $formData.append('file-' + i, $file.files[i]); } } var SnapShotReceivedData = [{ REASON: REASON_EXEMPT, COMMENT: COMMENT_EXEMPT, ATTACHMENT: $formData }]; SnapShotReceivedData = JSON.stringify({ 'SnapShotReceivedData': SnapShotReceivedData}) $formData.append('SnapShotReceivedData',SnapShotReceivedData); $.ajax({ contentType: false; processData: false, type: 'POST', url: '@Url.Action("SetHCMNIDSnapData", "Home")', data: $formData , success: function (result) { }, failure: function (response) { // $('#result').html(response); } });

Controlador:

 public JsonResult SetHCMNIDSnapData(List<SnapShot> SnapShotReceivedData) { if (Request.Files.Count > 0) { foreach (string file in Request.Files) { var _file = Request.Files[file]; } } }

mi modelo es SnapShotReceivedData . Cuando depuro el controlador, el objeto del modelo siempre es nulo. Por favor ayúdame a solucionar esto.

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!