English 中文(简体)
• 如何与我的Ajax.actionlink通过时段
原标题:How can i pass the timestamp with my Ajax.actionlink

i 具有fol光指数,显示物体清单和删除Ajax。 行动联系:

<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。 行动联系将称为以下行动方法:

        [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);

            }}

But currently if the user clicks on the Delete link and the record was modified by another user then no DbUpdateConcurrencyException will be raised ,, as i am not passing the timestamp to the delete action method... so how i can include the timestamp values with the Delete ajax.actionlink? //Hint the object already include a timestamp propert. BR

问题回答

你可以把它作为直截了当的参数通过,同样,你通过:

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

and then have the Delete controller action take a timestamp parameter.





相关问题
Getting exact error type in from DbValidationException

I have the situation where I m initializing my model in DatabaseInitializer() for EF 4.1 and get this annoying error "Validation failed for one or more entities. See EntityValidationErrors property ...

Entity framework 4 - custom complex type mapping

I have a poorly written legacy database schema that I m working with via EF Code First. I m currently mapping POCO entities and would like to create an "Address" complex type and use this everywhere ...

热门标签