【发布时间】:2011-01-31 23:39:27
【问题描述】:
假设用户删除了一条记录,然后按下返回箭头,并重新提交 POST 请求。
在处理这种情况时我有哪些选择?
什么是首选?
[HttpPost]
public ActionResult Delete(string EntryName, Guid id, FormCollection collection)
{
try
{
var ret = from m in _entities.MyList
where m.MyListID == id
&& m.EntryName == EntryName
select m ;
if (ret.Count() == 0)
{
// This happens if the user pressed the back button and resubmitted
// todo: ask SO what is the best way to approach this...
// User feedback? How?
return RedirectToAction("Index", new { id = id });
}
_entities.DeleteObject(ret.FirstOrDefault());
_entities.SaveChanges();
return RedirectToAction("Index", new { id = id } );
}
catch
{
return View();
}
}
【问题讨论】:
-
向他显示他要删除的内容不存在/已删除的通知。 :)
-
如何在 MVC 中完成 UI?
标签: asp.net-mvc error-handling asp.net-mvc-3 crud