C# 加载图像后删除图像

C# 加载图像后删除图像,c#,asp.net-mvc-4,visual-studio-2013,entity-framework-4,C#,Asp.net Mvc 4,Visual Studio 2013,Entity Framework 4,我想在上传后删除图像。上传后显示图像。但现在用户还必须获得删除图像的机会,但如果我选择一个图像并按delete nothing(删除),则会出现以下情况: <div id="tabs-3"> @using (Html.BeginForm("UploadMorePhotos", "Account", FormMethod.Post, new { enctype = "multipart/form-data" })) {

我想在上传后删除图像。上传后显示图像。但现在用户还必须获得删除图像的机会,但如果我选择一个图像并按delete nothing(删除),则会出现以下情况:

<div id="tabs-3">


           @using (Html.BeginForm("UploadMorePhotos", "Account", FormMethod.Post, new { enctype = "multipart/form-data" }))
           {
               @Html.AntiForgeryToken()


            <div class="form-field">
                <p>Select pictures:</p>
                <div class="upload-container">
                    <div class="upload">
                        <input type="file" name="files" value="" multiple="multiple" id="file1" />

                        <img src="@Url.Content("~/images/deleteButton.png")" alt="Remove picture." />
                    </div>
                </div>
            </div>

            <div class="form-field">
                <input type="submit" value="Upload" />
            </div>

    <br />

      foreach (var item in Model.LolaBikePhotos )
       {
        <img src="~/Images/profile/@item.ImagePath" alt="" height=150 width=200 />

           using (Html.BeginForm("Account", "DeleteFiles", FormMethod.Post, new { enctype = "multipart/form-data" }))
           {
            <table>
                <tr>
                    <td></td>
                    <td>File Name</td>
                </tr>


                    <tr>
                        <td>
                            <input type="checkbox" name="files" value="@item.ImagePath" />
                        </td>
                        <td>@item.ImagePath</td>
                    </tr>
                            </table>

            <input type="submit" value="Delete" />
           }




       }





           }

       <br />


        </div>
这是我的行动方法:

 [HttpPost]
        public ActionResult DeleteFiles(IEnumerable<HttpPostedFileBase> files)
        {
            foreach (var id in files)
            {
                var fileName = Path.GetFileName(id.FileName);
                var path = Path.Combine(Server.MapPath("~/Images/profile" + @"\" + fileName.Replace('+', '_')));
                var file = db.lolabikerPhotos.Find(id);

                // you now have access to the information of the file, including path, name, etc

                // delete file using your filepath (path + filename)
               System.IO.File.Delete(path);
            }


            return Redirect(Url.Action("Edit", "Account") + "#tabs-3");

        }

映像也没有从后端删除吗?您的应用程序对该文件夹有适当的删除权限?是的,它有适当的删除权限,但奇怪的是,如果我将断点放在删除操作方法上,它将不会被命中,并且我的正文标题正确吗?公共操作结果deleteFileSineumerable文件我做错了什么?某人很高兴能得到一些建议