How to append whole set of model to formdata and obtain it in MVC

If your view is based on a model and you have generated the controls inside <form> tags, then you can serialize the model to FormData using var formdata = new FormData($(‘form’).get(0)); This will also include any files generated with <input type=”file” name=”myImage” …/> and post it back using $.ajax({ url: ‘@Url.Action(“YourActionName”, “YourControllerName”)’, type: ‘POST’, data: … Read more

Sending multipart/formdata with jQuery.ajax

Starting with Safari 5/Firefox 4, it’s easiest to use the FormData class: var data = new FormData(); jQuery.each(jQuery(‘#file’)[0].files, function(i, file) { data.append(‘file-‘+i, file); }); So now you have a FormData object, ready to be sent along with the XMLHttpRequest. jQuery.ajax({ url: ‘php/upload.php’, data: data, cache: false, contentType: false, processData: false, method: ‘POST’, type: ‘POST’, // … Read more