.net editor and upload
.net editor and upload
Hi
I am trying to upload an image using the upload function i the datables editor and the .net backend.
I would like to use custom action and save the file in a custom folder on the webserver and just save the path in a field in the table the editor is using.
But whenever I try to add the
.Field(new Field("Billede")
.Upload(new Upload((file, id) => {
file.SaveAs(context.Request.PhysicalApplicationPath+@"Files\Images\Vouchers\"+file.FileName);
return @"Files\Images\Vouchers\" + file.FileName;
}))
)
I get an error saying "A value must not be null. Parametername: key" when loading the datatable?? If I remove the Upload from the Field, it works, but I cannot upload as no field is defined as upload.
Why is that? Am I approaching this wrong?
This question has an accepted answers - jump to answer
Answers
Hi,
The code looks good - I would expect that to work. Could you show me the model you are using? I'm wondering if the field (probably the
Billede
field) is nullable or not?Does the error occur before you've uploaded any files - i.e. immediately as soon as you add the above and the database contains null values for
Billede
(at least that is what I assume to be the case!)?Thanks,
Allan
In my model the 'Billede' (which is danish for picture) property is a string, so it should be nullable :-)
I have tried with both with and without data in the 'Billede' field in the database. Since I played with it most of last night, I am to tired to make a sample projekt right now.
I might do it tomorrow, if it would help.
It would certainly be interesting if that is possible. If not, I'll try to recreate the issue locally tomorrow myself.
Could you confirm if this happens on page load (i.e the Ajax request to get the data for the table) before any files have been uploaded, after a file has been uploaded and the page it reloaded or immediately after a file has been uploaded?
One other thing - are you using the 1.5.3 libraries for .NET?
Thanks,
Allan
Hi Allan,
Did not get a chance to make a POC project. The error occurs in the ajax load when the datatable tries to get the data.
Below is the actual part of the handler, that the table calls.
My VoucherType is defined as following:
And yes, I am using version 1.5.3 og the .net library
Ohh. I forgot to add the table as well.
Hi,
Sorry I haven't had a chance to look at this in detail yet. I've not forgotten about it and will get back to you as soon as possible!
Regards,
Allan
Hi Allan.
No worries... I haven't supplied you with a working sample project either. And I know you have other obligations as well. I've been quit busy with other projects, too.
Mikkel
HI Mikkel,
Thanks for your patience with this. It is without question a bug in the Editor libraries that is triggered when there is no
Db
method specified for the file upload. I've committed the fix locally and it will be part of Editor 1.5.4 which I expect to release soon (possibly tomorrow now).If you want to fix it immediately, in the
Editor.cs
file there is a method called_FileDataFields
- where thevar table = upload.Table();
is defined it should be:i.e. check if
table
is null or not. It is with the configuration you have and it is failing without that check.Regards,
Allan
Great thnx. I will look forward to 1.5.4 and update the code when it is released.