0

我有以下索引视图,显示对象列表和每个对象旁边的 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

4

1 回答 1

1

您可以将其作为查询字符串参数传递,就像传递 id 一样:

@Ajax.ActionLink(
    "Delete",
    "Delete", 
    "Visit",
    new { 
        id = item.VisitID,
        timestamp = item.Timestamp
    },
    new AjaxOptions
    {
        HttpMethod = "Post",
        OnSuccess = "deletionconfirmation",
        OnFailure = "deletionerror"
    }
)

然后让 Delete 控制器操作带一个timestamp参数。

于 2012-04-26T07:28:36.207 回答