I started working only yesterday. Somewhere my colModel column to upload files,
{ name: 'fileToUpload', index: 'customer_id', align: 'left', editable: true, edittype: 'file', editoptions: { enctype: "multipart/form-data" }, width: 210, align: 'center', formatter: jgImageFormatter, search: false }
You need to install afterSubmit: UploadImage . It only downloads the file after the data has been sent and the response has returned. I check here that if the insert was succesfful, then just start the download to still show an error. I used the jQuery Ajax File Uploader .
function UploadImage(response, postdata) { var data = $.parseJSON(response.responseText); if (data.success == true) { if ($("#fileToUpload").val() != "") { ajaxFileUpload(data.id); } } return [data.success, data.message, data.id]; } function ajaxFileUpload(id) { $("#loading") .ajaxStart(function () { $(this).show(); }) .ajaxComplete(function () { $(this).hide(); }); $.ajaxFileUpload ( { url: '@Url.Action("UploadImage")', secureuri: false, fileElementId: 'fileToUpload', dataType: 'json', data: { id: id }, success: function (data, status) { if (typeof (data.success) != 'undefined') { if (data.success == true) { return; } else { alert(data.message); } } else { return alert('Failed to upload logo!'); } }, error: function (data, status, e) { return alert('Failed to upload logo!'); } } ) }
source share