I decided to update this question as I still cannot change imageId
This is my current dropzone implementation.
$("div#UploadImage").dropzone({ url: '@Url.Action("SaveUploadedPhoto", "Listing", new { advertId = @Model.AdvertId })', addRemoveLinks: true, init: function () { var myDropzone = this; // First change the button to actually tell Dropzone to process the queue. $("input[type=submit]").on("click", function (e) { // Make sure that the form isn't actually being sent. e.preventDefault(); e.stopPropagation(); myDropzone.processQueue(); }); myDropzone.on("success", function (file, rep) { console.log(rep.UniqueId); fileList[i] = { "serverFileName": rep.UniqueId, "fileName": rep.UniqueId, "fileId": rep.UniqueId, "name": rep.UniqueId }; i++; console.log(fileList); }); myDropzone.on("removedfile", function (file) { var rmvFile = ""; for (f = 0; f < fileList.length; f++) { if (fileList[f].fileName == file.name) { rmvFile = fileList[f].serverFileName; } } if (rmvFile) { $.ajax({ url: '@Url.Action("DeleteUploadedFile", "Listing")', type: "POST", data: { "id": rmvFile } }); } }); }, maxFilesize: 2, maxFiles: 12 });
When I upload an image, we transfer the image to a third party company that returns a uniqueId for this image, this uniqueId is then stored in my database, then I pass this uniqueId back to the view, which will become the loaded image name, I'm trying to do this in the function " success "in the above dropzone implementation when I do
console.log(rep.UniqueId);
I see the meaning and its correct.
When I click "Delete Image" in dropzone, the "removeFile" function is called, it does not work for the controller, because rmvFile is the old image name, and it does not find a match in the for loop, I know this because when I do
console.log(rmvFile);
It shows the old name, now my question is what am I doing wrong here? How can I change the name of the downloaded image or identifier to uniqueId, which is returned after the download is complete? so i can successfully remove it as needed.
I looked at the website, tried a situation that led to what my success method looks like.