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

127
Views
La llamada Ajax no pasa el objeto al controlador

Estoy tratando de pasar una cadena a una función IActionResult en un controlador asp.net core 3.1.

Ajax:

 function CreateApprover() { const input = { PlantId: $('#ddlPlant').val(), UserId: $('#ddlUser').val(), CategoryId: $('#ddlCategory').val() }; let jsonData = JSON.stringify(input); console.log(jsonData); $.ajax({ contentType: "application/json", data: jsonData, traditional: true, method: "POST", url: "@Model.CreateUrl", success: function (data, textStatus, jqXHR) { dialogDiv.dialog('close'); }, error: function (xhr, err) { console.log(arguments); console.log('Request Status:'); console.log(xhr.status); console.log('Status Text:'); console.log(xhr.status); console.log(xhr.responseText); } }); }

Información de red:

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

C#:

 [HttpPost] public IActionResult CreateApprover(IFormCollection keyValues, [FromBody]ApproversCreateModel input) { return Ok(); } public class ApproversCreateModel { public int UserId { get; set; } public int PlantId { get; set; } public int CategoryId { get; set; } }

La carga útil parece correcta y los puntos de interrupción se alcanzan en el método del controlador, pero el parámetro de entrada siempre es nulo y el parámetro keyValues no tiene datos. ¿Qué me estoy perdiendo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Respondido por Bryan Dellinger,

tal vez pruebe PlantId: parseInt($('#ddlPlant').val()), etc.

over 4 years ago · Santiago Trujillo 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!