我有一个folloiwng Index视图,它显示了一个对象列表,并在每个对象旁边显示了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
,因为我没有将时间戳传递给删除操作方法...所以如何我可以在Delete ajax.actionlink中包含时间戳值吗?
//提示对象已包含时间戳属性。
BR
答案 0 :(得分:1)
您可以将其作为查询字符串参数传递,与传递ID的方式相同:
@Ajax.ActionLink(
"Delete",
"Delete",
"Visit",
new {
id = item.VisitID,
timestamp = item.Timestamp
},
new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "deletionconfirmation",
OnFailure = "deletionerror"
}
)
然后让删除控制器操作采用timestamp
参数。