I'm using Dropzone.js library, when I add a photo to the gallery it works fine, but when I try to remove the photo from the gallery it just removes the photo in my View >, but does not remove it from the folder itself.
I pass the ID and the name of the image as a parameter. The id arrives right, but the image name is null.
@foreach (var image in Model.Galeria)
{
<div style="display: inline-block;margin-right: 15px;">
<img src="/Images/Uploads/Produto/@Model.Produto.Id/Gallery/Thumbs/@image" />
@Html.ActionLink("Deletar", "DeletarImagem", "Produto", new { @class = "deleteimage", data_name = image })
</div>
}
Delete function:
$("a.deleteimage").click(function (e) {
e.preventDefault();
if (!confirm("Confirm deletion")) return false;
var $this = $(this);
var url = "/Produto/DeletarImagem";
var imageName = $this.data("image");
$.post(url, { id: @Model.Produto.Id, imageName: imageName }, function(data) {
$this.parent().fadeOut("fast");
});
});
My action where the id arrives correctly, but image name is arriving null:
[HttpPost]
public void DeletarImagem(int id, string nomeimagem)
{
string caminhocompleto1 = Request.MapPath("~Images/Uploads/Produto/" + id.ToString() + "/Gallery/" + nomeimagem);
string caminhocompleto2 = Request.MapPath("~Images/Uploads/Produto/" + id.ToString() + "/Gallery/Thumbs" + nomeimagem);
if (System.IO.File.Exists(caminhocompleto1))
System.IO.File.Delete(caminhocompleto1);
if (System.IO.File.Exists(caminhocompleto2))
System.IO.File.Delete(caminhocompleto2);
}