【发布时间】:2012-12-28 15:05:52
【问题描述】:
这是一个将图像设置为ViewBag 以供显示的操作。
public ActionResult UploadPhoto()
{
List<string> images = new List<string>();
foreach (var file in Directory.GetFiles(AlbumManager.GetAlbumName(SessionManager.CurrentSession.PropertyId, true)))
{
images.Add(Server.RelativePath(file));
}
ViewBag.Images = images;
return PartialView("UploadPhoto");
}
这是一个用于删除所选图像的发布操作。
[HttpPost]
public ActionResult DeletePhoto(string imageName)
{
AlbumManager.DeletePhoto(SessionManager.CurrentSession.PropertyId, imageName);
return UploadPhoto();
}
如您所见,删除完成后,我会将其重定向到必须打印当前存在的图像的UploadPhoto 操作。但是在回发后,删除的图像仍在显示。我非常不确定这种行为。请帮我解决这个问题。
我尝试使用以下代码清除 DeletePhoto 操作中的模型状态,但没有用。
ModelState.Clear();
我的观点:
@using (Html.BeginForm("DeletePhoto", "Add", FormMethod.Post, new { id = "PhotoDelete" }))
{
<input type="hidden" name="imageName" id="imageName" />
<div class="thumnailsBox">
@foreach (var image in ViewBag.Images)
{
<div class="thumnailTails">
<span class="thumbimage">
<input id="imageSubmit" type="image" alt="No Image" src="@Url.Content(image)" /></span>
</div>
}
</div>
}
解决方案:
除了IronMan84的回答,这里是我的问题的实际解决方案:
[HttpPost]
public ActionResult DeletePhoto(string imageName)
{
AlbumManager.DeletePhoto(SessionManager.CurrentSession.PropertyId, imageName);
return JavaScript("location.reload(true)");
}
我正在渲染一个脚本以在此处重新加载页面。
【问题讨论】:
-
您能发布您的查看代码吗?我想看看 UploadPhoto 的 PartialView 去哪里了。
-
@IronMan84 - 更新了问题。
标签: asp.net-mvc-3 image modelstate