我有以下索引视图,显示对象列表和每个对象旁边的 Delete Ajax.actionlink:-
<legend>@Model.Where(d => d.VisitStatu.Description.ToUpper().Equals("ASSINGED")).Count() @ViewBag.subtitle</legend>
<table>
<tr>
<th>Patient Full Name </th>
<th>Created BY</th>
<th></th>
</tr>
@foreach (var item in Model.Where(d => d.VisitStatu.Description.ToUpper().Equals("ASSINGED")))
{
<tr id = @item.VisitID>
<td>@Html.DisplayFor(modelItem => item.Patient.FullName)</td>
<td>@Html.DisplayFor(modelItem => item.CreatedBy)</td>
<td>@Ajax.ActionLink("Delete",
"Delete", "Visit",
new { id = item.VisitID },
new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "deletionconfirmation",
OnFailure = "deletionerror"
}
</td> </tr>
Ajax.actionlink 将调用以下 Post Action 方法:-
[HttpPost]
public ActionResult Delete(int id)
{ try
{ var v = repository.GetVisit(id);
if (!(v.Editable(User.Identity.Name)))
{return View("NotFound"); }
repository.DeleteVisit(v);
repository.Save();
return Json(new { IsSuccess = "True", id = id, description = v.Date.ToString() }, JsonRequestBehavior.AllowGet);
}
catch (DbUpdateConcurrencyException)
{
return Json(new { IsSuccess = "False" }, JsonRequestBehavior.AllowGet);
}
catch (OptimisticConcurrencyException)
{
return Json(new { IsSuccess = "False" }, JsonRequestBehavior.AllowGet);
}}
但是目前,如果用户单击“删除”链接并且记录被另一个用户修改,则不会DbUpdateConcurrencyException
引发,因为我没有将时间戳传递给删除操作方法......所以我如何将时间戳值包含在删除 ajax.actionlink?//提示对象已经包含时间戳属性。BR