2012-04-25 64 views
0

我有显示对象的列表和每个对象旁边一个删除Ajax.actionlink的folloiwng索引视图: -如何传递时间戳与我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操作方法: -

 [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将提高修改,,因为我没有通过时间戳的删除行动方法...所以我如何包括时间amp的值与删除ajax.actionlink? //提示该对象已包含timestamp属性。 BR

回答

1

你可以把它作为查询字符串参数,您传递的ID以同样的方式:

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

,然后在这个删除控制器动作采取timestamp参数。

+0

感谢您的回复,但是我如何告诉Post操作方法在发送到数据库的删除请求中包含时间戳? – 2012-04-26 11:59:32

+0

@johnG,这个问题与ASP.NET MVC不再有任何关系。请开始一个新的线程,在那里你解释你的数据库结构,你正在使用的数据访问技术,如果你正在使用一个ORM如EF来显示你的模型类...... – 2012-04-26 13:55:37