假設用戶刪除一條記錄,然後按下後退箭頭,然後重新提交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();
}
}
那邊尼斯TODO註釋顯示給他的通知,他試圖刪除不存在什麼/已被刪除。 :) – 2011-01-31 23:41:00