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.
Intente inicializar su detalle con un objeto en lugar de una matriz:
const saveDetail = []; // wrong const saveDetail = {}; // correctver esta página para referencia