Просмотр кода:
@if (File.Exists(Server.MapPath("~/Images/Cakes/" + Html.DisplayFor(modelItem => Model.CakeImage))))
{
@model TastyCakes.Models.Cakes
<form name="deletePhoto" action="/Cakes/DeletePhoto" method="post">
@Html.AntiForgeryToken()
File name of image to delete (without .jpg extension):
<input name="photoFileName" type="text" value="@Html.DisplayFor(modelItem => Model.CakeImage)" />
<input type="submit" value="Delete" class="tiny button">
</form>
} else {
<p>*File Needs to be uploaded</p>
}
Код контроллера:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DeletePhoto(string photoFileName)
{
ViewBag.deleteSuccess = "false";
var photoName = "";
photoName = photoFileName;
var fullPath = Server.MapPath("~/Images/Cakes/" + photoName);
if (File.Exists(fullPath))
{
File.Delete(fullPath);
ViewBag.deleteSuccess = "true";
}
}
Где он говорит, что (File.Exists) AND File.Delete, код имеет под ним строчки. Поэтому я пытаюсь выяснить, какой синтаксис мне нужен, чтобы удалить файл thif.
Вот скриншот моего кода в контроллере:
UPPDATE: У меня есть код, который работает и создал простой пример кода в моем блоге о том, как я получил его работу и как появилась идея. http://httpjunkie.com/2014/724/mvc-5-image-upload-delete/