Jqgrid - load a file in the add / edit dialog

I am new to jqgrid and I have learned a lot from your answer.
Now I have a problem: do I want to upload files when adding or changing records in jqgrid?

This is my code:

{ name: 'File', index: 'file', hidden: true, enctype: "multipart/form-data", editable: true, edittype: 'file', editrules: { edithidden: true, required: true }, formoptions: { elmsuffix: '*' } } 



However, the field that I received in the controller is always null :( Any suggestion
Does anyone know a working example?
thanks in advance

UPDATE
I found a very good example at http://tpeczek.codeplex.com/releases

+6
source share
1 answer

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!'); } } ) } 
+5
source

Source: https://habr.com/ru/post/898034/


All Articles