Tut*_*uta 1 asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4
我正在使用MVC5项目,我创建了一个简单的系统,用户可以为每个Employee上传文件"CV".现在除了"DELETING File"之外,所有的事情对我都很好.我需要添加删除上传文件的操作方法以及用另一个文件替换它的功能.
在模型类中,我创建了两个属性HttpPostedFileBase CV来保存上传的文件和String cvName,以保存文件名并使用它来创建指向该文件的链接.
在控制器中我做了什么:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DeleteCV(string cvName)
{
//Session["DeleteSuccess"] = "No";
var CVName = "";
CVName = cvName;
string fullPath = Request.MapPath("~/Content/CVs/" + CVName);
if (System.IO.File.Exists(fullPath))
{
System.IO.File.Delete(fullPath);
//Session["DeleteSuccess"] = "Yes";
}
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
这是观点:
<div class="form-group">
@Html.LabelFor(model => model.CV, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@{
if (File.Exists(Server.MapPath("~/Content/CVs/"
+ Html.DisplayFor(model => model.cvName))))
{
<a href="~/Content/CVs/@Html.DisplayFor(model => model.cvName)"> @Html.DisplayFor(model => model.cvName) @Html.HiddenFor(model => model.cvName)</a>
<a href="@Url.Action("DeleteCV", new { @Model.cvName })">
<img src="@Url.Content("~/Content/Images/Delete.jpg")" width="20" height="20" class="img-rounded" />
</a>
}
else
{
<input type="file" name="file" accept="pdf" />
}
}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
每次出现此消息时,我都无法删除该文件
无法找到该资源.
说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用.请查看以下网址,确保拼写正确.
请求的URL:/ DeleteCV
归档时间: |
|
查看次数: |
1433 次 |
最近记录: |