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

616
Views
Enviar archivo desde JQuery Ajax a C# Webmethod

Quiero enviar datos desde la página aspx a .cs Webmethod usando jQuery Ajax. mi código html es como se muestra a continuación

 <tr> <td> <input type="text" id="txtName"> </td> </tr> <tr> <td> <form action="" id="AttachmentForm1" enctype="multipart/form-data"> <input type="file" name="UploadFile1" id="txtUploadFile1" class="btn btn-sm" /> </form> </td> </tr>

Y mi código javascript como se muestra a continuación

 function saveData() { var file = $("#txtUploadFile1")[0].files[0]; $.ajax({ url: 'CCA_Form.aspx/SaveData', type: 'POST', dataType: 'json', contentType: 'application/json; charset=utf-8', data: JSON.stringify({ Name: txtName, fileData: file }), success: function () { alert("Data Added Successfully"); }, error: function () { alert("Error while inserting data"); } });}

Y mi código c# como se muestra a continuación

 [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static bool SaveData(string Name, string[] fileData) { //Breakpoint return true; }

¿Cómo puedo cargar un archivo en Webmethod en C#?

Gracias por adelantado.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Necesitas hacer usando XMLHttpRequest
Estos chicos tienen un muy buen tutorial al respecto. miralo si te sirve: click aqui

O

Para su código anterior:

 var filename = $("#txtUploadFile1").val(); $.ajax({ url: 'CCA_Form.aspx/SaveData', type: 'POST', enctype: 'multipart/form-data', data: {file: filename}, success: function () { alert("Data Added Successfully"); }, error: function () { alert("Error while inserting data"); } });}
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!