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

115
Views
cargar el tipo de archivo usando ajax en el cliente principal de asp.net

este es mi html

 <form enctype="multipart/form-data" class="needs-validation" id="formRequestLeave2"> <div class="row form-group"> <label class="col-md-4" for="File"><strong>Upload File</strong></label> <div class="col-md-7 form-control"> <input class="form-control custom-file-input" id="fileUpload" name="File" type="file" required> <label class="custom-file-label">Choose File...</label> </div> </div> </form>

este es mi javascript

 function Insert() { event.preventDefault(); var obj = new Object(); obj.EmployeeId = $("#employeeId2").val(); obj.File = $("#fileUpload").val(); manager = $("#managerName2").val() $.ajax({ url: "/LeaveDetails/LeaveRequest", type: "POST", 'data': obj, }) }

este es mi controlador

 public JsonResult LeaveRequest(LeaveRequestVM leaveRequestVM) { string uniqueFileName = null; if (leaveRequestVM.File != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "files"); uniqueFileName = Guid.NewGuid().ToString() + "_" + leaveRequestVM.File.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); leaveRequestVM.File.CopyTo(new FileStream(filePath, FileMode.Create)); } leaveRequestVM.uniqueFileName = uniqueFileName; var result = repository.LeaveRequest(leaveRequestVM); return Json(result); }

Estoy tratando de enviar una entrada de tipo de archivo a mi controlador desde mi vista usando ajax pero salió nulo. He estado tratando de usar

 contentType: false, processData: false
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 <form id="frmproduct" method="post" asp-antiforgery="true" class="row gy-1 pt-75" onsubmit="return false"> <span class="btn btn-primary btn-sm btn-file"> <input type="file" name="Image"> </span> </form> <script> frmproduct.onsubmit = async (e) => { e.preventDefault(); if (!$("#frmproduct").valid()) return false; let response = await fetch('/base/product/Create', { method: 'POST', body: new FormData(frmproduct) }); let data = await response.json(); }; </script>

y obtenga el archivo del controlador

 [HttpPost, ValidateAntiForgeryToken] public async Task<JsonResult> Create(ProductViewModel model, CancellationToken cancellationToken) { var File= Request.Form.Files; }
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!