Errors with uploadMany
Errors with uploadMany
dynasoft
Posts: 446Questions: 69Answers: 3
Hi
Errors are cropping up when loading the page and the datatable and when trying to upload a file (after I comment out the part where d.length is mentioned):
- Uncaught TypeError: Cannot read property 'length' of undefined
- jquery-3.3.1.min.js:2 POST http://localhost:6301/CDRData/CRUDCDRDataAndFiles/ 500 (Internal Server Error)
My code:
JS:
var editor1 = new $.fn.dataTable.Editor({ ajax: { url: '/CDRData/CRUDCDRDataAndFiles/', data: { intCdrFrmtSrc: intCdrFrmtSrc1, intCdrFrmtTpe: intCdrFrmtTpe1, strCdrFrmtNme: strCdrFrmtNme1 }, type: 'POST', async: true, cache: false }, table: '#tblCDRDataAndFilesTable', fields: [ { label: '@(lblo.lblUploadedFile)*:', name: 'UserFiles[].UserFileID', type: 'uploadMany', display: function ( id, counter ) { return id ? "SomeLink" : null; }, clearText: '@(lblo.lblClear)', noFileText: '@(lblo.lblNoFile)' } ], i18n: { error: { system: '@(lblo.lblError5)' } } }); var dataTable = $('#tblCDRDataAndFilesTable').DataTable( { destroy: true, order: [[0, 'desc']], columnDefs: [ { 'bVisible': false, 'targets': 0 }, { targets: [0,1], className: 'text-center' } ], dom: 'Bfrtip', ajax: { url: '/CDRData/CRUDCDRDataAndFiles/', data: { intCdrFrmtSrc: intCdrFrmtSrc1, intCdrFrmtTpe: intCdrFrmtTpe1, strCdrFrmtNme: strCdrFrmtNme1 }, type: 'GET', dataType: 'json', contentType: 'application/json; charset=utf-8', async: true }, columns: [ { data: 'id' , className: 'text-left' }, { data: "UserFiles", //*HERE* render: function ( d ) { return d.length ? d.length+' image(s)' : '@(lblo.lblNoFile)'; }, className: 'text-left', defaultContent: '@(lblo.lblNoFile)', title: '@(lblo.lblFile)' } ], select: true, buttons: [ { extend: 'create', editor: editor1 }, { extend: 'edit', editor: editor2 }, { extend: 'remove', editor: editor2 } ] });
Server:
public static DtResponse CRUDCDRDataAndFiles(int intCdrFrmtSrc, int intCdrFrmtTpe, string strCdrFrmtNme) { Editor editor = null; try { HttpRequest formData = System.Web.HttpContext.Current.Request; using (Database db = new Database(SetGetDbType2, SetGetDbConnection)) { editor = new Editor(db, "AutoCDRFiles").Model<CDRDataDBModel>(); editor.Field(new Field("id") .Set(false) ); editor.Field(new Field("UserFileID") .SetFormatter(Format.IfEmpty(null)) .Upload(new Upload(strFolder + @"\__NAME____EXTN__") .Db("UserFiles", "id", new Dictionary<string, object> { {"WebPath", Upload.DbType.WebPath}, {"SystemPath", Upload.DbType.SystemPath}, {"FileName", Upload.DbType.FileName}, {"FileSize", Upload.DbType.FileSize} }) ) ); if (intCdrFrmtSrc > -1) editor.Where("CDRSourceType", intCdrFrmtSrc); if (intCdrFrmtTpe > -1) editor.Where("CDRDataType", intCdrFrmtTpe); if (intCdrFrmtTpe > -1) editor.Where("CDRName", strCdrFrmtNme); editor.TryCatch(false); editor.Debug(true); editor.Process(formData); editor.Data(); } return editor.Data(); }
Many thanks
This discussion has been closed.
Answers
Hi
For error #1, I had to use UserFileID as the column reference to fix it:
For the 2nd error if I use this:
I'm able to create and update all the fields except for the upload one. What is the correct syntax to use to work with "standard2 fields and uploads fields? Thank you.
with "standard" fields and uploads fields
Hi
I'd like to keep using parameters if I can as above.
I'm afraid I don't quite understand what you are looking for. Could you elaborate on this a little more for me please?
Thanks,
Allan
Hi
I'd like to use ajax parameters like this when working with upload functionality:
ajax: {
url: '/CDRData/CRUDCDRDataAndFiles/',
data: {
intCdrFrmtSrc: intCdrFrmtSrc1,
intCdrFrmtTpe: intCdrFrmtTpe1,
strCdrFrmtNme: strCdrFrmtNme1
},
type: 'POST',
async: true,
cache: false
}
But I get a (Internal Server Error). I don't get this error if I do not use any upload code in my page, ie work with json data. The only format that will work is working w/ uploads is this:
But under MVC, I then have to fiddle round with routes which I'd like to avoid.
The only format that will work is working w/ uploads is this:
should read:
The only format that will work working w/ uploads is this:
The
upload
field type (anduploadMany
) has aajaxData
option which can be used to send extra information to the server - e.g.:Allan
Hi
Thanks. Should I replace this:
ajax: { //works
url: '/CDRData/CRUDCDRDataAndFiles/' + intCdrFrmtSrc1.toString() + '/' + intCdrFrmtTpe1.toString() + '/' + strCdrFrmtNme1,
}
with this:
I tried but get a 500 error.
The controller action is this one:
Hi
Have been trying a few things and found the following works well: