简体   繁体   中英

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.

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM