大家好,我有一个文本框和一个文件上传控件和一个表格来显示上传的文件......我的表格中有一个删除链接......这样用户可以在点击提交按钮之前删除任何上传的文件...... .为此我有模型
public BugModel()
{
if (ListFile == null)
ListFile = new List<BugAttachment>();
}
public List<BugAttachment> ListFile { get; set; }
}
public class BugAttachment
{
public string FileName { get; set; }
public int BugAttachmentID { get; set; }
public string AttachmentName { get; set; }
public int BugID { get; set; }
public string AttachmentUrl { get; set; }
public string AttachedBy { get; set; }
public string ErrorMessage { get; set; }
}
当用户上传文件时,我将它们保存在 Listfile 列表中并将它们显示在表中。现在我想要从服务器和 Listfile 中删除上传的文件。我已经成功从上传的文件夹中删除了文件...现在,当用户单击删除链接时,我也想从 ListFile 中删除 AttachmentName 和 AttachmentUrl ..我应该怎么做..任何想法都非常感谢
这就是我到目前为止所做的
public ActionResult Delete(string FileName, BugModel model)
{
if (Session["CaptureData"] == null)
{
}
else
{
model = (BugModel)Session["CaptureData"];
}
char DirSeparator = System.IO.Path.DirectorySeparatorChar;
string FilesPath = ";" + FileName;
string filenameonly = name + Path.GetFileName(FilesPath);
string FPath = "Content" + DirSeparator + "UploadedFiles" + DirSeparator + filenameonly;
// Don't do anything if there is no name
if (FileName.Length == 0) return View();
// Set our full path for deleting
string path = FilesPath + DirSeparator;
// Check if our file exists
if (System.IO.File.Exists(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + FPath)))
{
// Delete our file System.IO.File.Delete(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + FPath));
}
return View("LoadBug");
}