user2484719
user2484719

Reputation: 1

how to delete file in asp.net mvc using jquery

my script

$("#btnDelete").click(function () {
    $.post(url, { fileName: _fileNameAttachementPhoto }, function (data) {
        $("#ResumePart4").html(data);
    });
});

my controllers

[HttpPost]
public ActionResult DeleteConfirmed(string fileName)
{
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
    FileInfo file = new FileInfo(path);
    if (file.Exists) {
        file.Delete();
    }
    return RedirectToAction("DeleteConfirmed");
}

I tried do this but nothing happened.

Upvotes: 0

Views: 1861

Answers (1)

Amit
Amit

Reputation: 15387

Try this

 $.post('@Url.Action("DeleteConfirmed", "ControllerName")',
            {
                fileName: FileName
            });

Upvotes: 3

Related Questions