如何处理两个用户删除同一个对象的情况

时间:2012-03-14 02:48:57

标签: jquery ajax asp.net-mvc-3

我有以下ajax.actionlink用于删除视图中的对象: -

 @{ string i = "Are uou sure you want to delete " + @answer.Description.ToString() + " ?";}
         @Ajax.ActionLink("Delete", "Delete", "Answer",
        new { id = answer.AnswersID },
          new AjaxOptions
          {
              Confirm = i,
              HttpMethod = "Post",
              OnBegin = string.Format(
                       "disablelink({0})",
                       Json.Encode(answer.AnswersID)),
              OnSuccess = string.Format(
                        "deleteconfirmation3({0})",
                        Json.Encode(answer.AnswersID))
          })

将调用以下Post操作方法: -

 [HttpPost]
        public void Delete(int id)
        {       var a = repository.FindAnswer(id);
                repository.DeleteAnswer(a);
                repository.Save();}

目前,如果两个用户访问同一个视图,然后他们都点击了与同一个对象关联的删除链接,那么将在其中一个请求上引发空异常;那么我如何在动作方法方面和视图方面处理此问题以向用户显示友好消息? BR

0 个答案:

没有答案