I have a pure HTML5 front end and an ASP.Net Core Web API running on a separate server. So far I've looked at examples that work only when I'm running these in the same ASP.Net application. But I've seen none that work when the front end is strictly HTML5 issuing an asynchronous AJAX request (That's AJAX with, and not without, the first A). My attempts to use iFormFile in the controller are blank using a standard AJAX POST. I've tried this with and without a multi-part form. I'm trying to implement it using this Stack OverFlow post: Uploading File using Ajax in Asp.Net Core
-
Well, the linked question has complete answers that should work for you. What is the exact problem you're having?Chris Pratt– Chris Pratt2019-04-08 18:07:41 +00:00Commented Apr 8, 2019 at 18:07
-
The iFormFile object is empty when called from the client via AJAX: var input = document.getElementById(inputId); var files = input.files; var formData = new FormData(); for (var i = 0; i != files.length; i++) { formData.append("files", files[i]); }user3662422– user36624222019-04-10 11:44:46 +00:00Commented Apr 10, 2019 at 11:44
-
And the AJAX call $.ajax( { url: apiUrl, data: formData, processData: false, contentType: false, type: "POST", success: function (data) { alert("Files Uploaded!"); }user3662422– user36624222019-04-10 11:52:58 +00:00Commented Apr 10, 2019 at 11:52
-
The controller is being called correctly but the IFormFile object is empty. I verified in the debugger that FormData does contain my file collection prior to the AJAX post.user3662422– user36624222019-04-10 11:54:35 +00:00Commented Apr 10, 2019 at 11:54
-
BTW this solution does work when I create an ASP.Net project where the client is a RAZOR component.user3662422– user36624222019-04-10 11:56:29 +00:00Commented Apr 10, 2019 at 11:56
Add a comment
|