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

110
Views
Cómo pasar la lista de objetos al método por ajax MVC

Hola a todos, quiero pasar la lista en la llamada ajax pero en mi controlador obtengo datos nulos

aquí está mi código

Clase

 public class CurrentProcessNameAndBucketName { public string ProcessName { get; set; } public string BucketName { get; set; } public int Id { get; set; } public int AccountId { get; set; } public int FromProcessId { get; set; } public int FromBucketId { get; set; } public int ToProcessId { get; set; } public int ToBucketId { get; set; } public string FromRefField { get; set; } public string ToRefField { get; set; } public int UserId { get; set; } }

controlador

 [HttpPost] [Authorize] [Route("api/Master/Workflow/InsertRefFieldClone")] public bool InsertRefFieldClone(List<BusinessEntities.Master.CurrentProcessNameAndBucketName> item) { try { BusinessLayer.IMaster.IWorkflow a = (BusinessLayer.IMaster.IWorkflow)DALFinder.GetInstance(typeof(BusinessLayer.IMaster.IWorkflow)); for (var i = 0; i < item.Count(); i++) { a.InsertRefFieldClone(item[i]); } return true; } catch (Exception ex) { Utils.Logger.Instance.LogException(ex); return false; } }

mi frente

 const saveDetails = []; const dataLength = tbody_Copy.children().length; for (let i = 0; i < dataLength; i++) { const saveDetail = []; saveDetail.Id = 0; saveDetail.AccountId = Utils.getCurrentUser().AccountId; saveDetail.FromProcessId = ctrlProcess.val(); saveDetail.FromBucketId = ctrlBucket.val(); saveDetail.ToProcessId = processId; saveDetail.ToBucketId = bucketId; saveDetail.FromRefField = $('#' + tbody_Copy.children().eq(i).find('SELECT').attr('id')).val(); saveDetail.ToRefField = tbody_Copy.children().eq(0).children().eq(1).text(); saveDetail.UserId = Utils.getUserId(); saveDetails.push(saveDetail); } const data = saveDetails; var access_token = Utils.getToken(); $.ajax({ url: Utils.getWebApiUrl() + "/api/Master/Workflow/InsertRefFieldClone", contentType: 'application/json; charset=utf-8', data: JSON.stringify(data), dataType: 'json', type: 'POST', beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'bearer ' + access_token); }, success: function (response) { debugger }, failure: function (response) { Utils.showError(JSON.stringify('Records cannot be saved please try again later.')); }, error: function (response) { Utils.showAlert(response.responseText); } });

No entiendo qué está mal en mi código, me parece bien pero no funciona. Vi muchos ejemplos y preguntas en línea e incluso en stackoverflow, pero aún así este problema no se resolvió.

la ayuda sería apreciada.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente inicializar su detalle con un objeto en lugar de una matriz:

 const saveDetail = []; // wrong const saveDetail = {}; // correct

ver esta página para referencia

about 4 years ago · Juan Pablo Isaza Report
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!