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

273
Views
enviar datos del cliente (vanilla js) a la API central de .net

cliente javascript vainilla (traté de hacerlo con axios/ajax/fetch)

 const myForm = document.getElementById("myForm"); myForm.addEventListener("submit", (e) => { debugger; var name = document.getElementById("errorInput").value; var description = document.getElementById("errorDescriptionInput").value; var date = document.getElementById("errorDateInput").value; var mail = document.getElementById("senderEmailInput").value; var file = document.getElementById('fileInput').files[0]; var formData = new FormData(); formData.append('fileInput', file); const error = { ErrorName: name, ErrorDescription: description, ErrorSubmittedDate: date, SenderEmail: mail, Documents: formData, } axios.post("https://localhost:44310/api/Error/senderror","sendFile", error, { "Content-Type": "multipart/form-data", "Content-Type": "application/json", }) })

API del controlador .net

 [EnableCors("policy")] [HttpPost] [Route("senderror")] public async Task<IActionResult> HandleError([FromForm]ErrorModel error) { return Ok(); }

El depurador del navegador muestra que el modelo contiene los valores, pero los datos que llegan al controlador son nulos. ¡Gracias por toda la ayuda!

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

0

Está enviando su archivo en formdata dentro de su objeto de error y en la API que ha aplicado

 [FromForm]

por lo tanto, el servidor espera los datos en forma y está enviando un objeto que contiene datos de forma. Creo que si agrega todos los datos en formdata, entonces funcionaría porque su API está esperando datos en formdata. Cámbielo así

 const myForm = document.getElementById("myForm"); myForm.addEventListener("submit", (e) => { debugger; var name = document.getElementById("errorInput").value; var description = document.getElementById("errorDescriptionInput").value; var date = document.getElementById("errorDateInput").value; var mail = document.getElementById("senderEmailInput").value; var file = document.getElementById('fileInput').files[0]; var formData = new FormData(); error.append('ErrorName', name); error.append('ErrorDescription', description); error.append('ErrorSubmittedDate', date); error.append('SenderEmail', file); error.append('Documents', mail); axios.post("https://localhost:44310/api/Error/senderror","sendFile", error, { "Content-Type": "multipart/form-data", }) })

tienes que configurar

 "Content-Type": "multipart/form-data",
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!