Skip to main content

Posts

Showing posts from 2019

ASP.NET CORE File Upload along with Complex Object with AJAX

Problem Area: In one of my project, my requirement was to Post File along Complex object to server using AJAX. I could not find ready made solution targeting both things in a single project so I decided to share this solution with you guys to try it out as well. HTML: <input type="file" id="uploadEditorImage" />  <input type="button" id="upload" value="upload" onclick="uploadImage()" /> Javascript: function uploadImage()     {         var userObj = {};         userObj.userId = "123456";         var serializedObj = JSON.stringify(userObj);         var formData = new FormData();         formData.append('file', $('#uploadEditorImage')[0].files[0]);         formData.append('vm', serializedObj );         var _urlAction = '@Url.Action("Upload", "Home")';         $.ajax({   ...