[英]how can I show the user that the data is gone when he trying to edit a field?
so when the user click the edit link to edit one of the client (field) and another user have erase already that client how can show to the user that the client (field) is gone? 因此,当用户单击编辑链接来编辑一个客户端(字段)而另一个用户已经擦除该客户端时,如何向用户显示该客户端(字段)已消失?
so I'am using TempData is another way to do it? 所以我使用TempData是另一种方式吗? i think jquery but i don't know how to use it properly
我认为jQuery,但我不知道如何正确使用它
public ActionResult Edit (int id)
{
client cliente = db.Clients.Find(id);
if (cliente != null)
{
return View(cliente);
}
TempData["message"] = string.Format("this client have be erase for other user");
return RedirectToAction("Index");
}
edit: 编辑:
and view is this 和视图是这个
<table class="widgets">
<tr>
<th></th>
<th>
@Html.ActionLink("Nombre", "Index", new { ordenacion = ViewBag.NameSortParm, filtro = ViewBag.filtro })
</th>
</tr>
@foreach (var item in Model) {
<tr id="widget-id-@item.id">
<td>
@Html.ActionLink("Editar", "Edit", new { id=item.id }) |
@Ajax.ActionLink("Eliminar", "Eliminar", "Cliente",
new {item.id },
new AjaxOptions {
HttpMethod = "POST",
Confirm = string.Format("Esta Seguro que quiere eliminar '{0}'?", item.descripcion),
OnSuccess = "deleteConfirmation"
})
</td>
<td>
@Html.DisplayFor(modelItem => item.descripcion)
</td>
</tr>
}
</table>
i guees the script will be this? 我猜剧本是这个吗? so i have to make my edit link like i did for the delete (eliminar) link using @Ajax.ActionLink right?
所以我必须像使用@ Ajax.ActionLink进行删除(删除)链接一样,使我的编辑链接正确吗?
<script type="text/javascript">
var validateForEdit = function (id) {
var validateCallbackFunction = function (result) {
if (result) {
window.location = '/Client/Editar/' + id;
}
else {
window.Alert('this client have be erase for other user');
}
};
$.post('/Client/ValidateForEdit/', { id: id }, validateCallbackFunction, 'json');
}
</script>
Hi you can use following code to validate data before user can edit that 嗨,您可以使用以下代码来验证数据,然后用户才能对其进行编辑
var validateForEdit = function (id) {
var validateCallbackFunction = function (result) {
if (result) {
window.location = '/Client/Edit/' + id;
}
else {
Alert('this client have be erase for other user');
}
};
$.post('/Client/ValidateForEdit/', { id: id }, validateCallbackFunction, 'json');
}
And your Action : 和你的行动:
[HttpPost]
public JsonResult ValidateForEdit(int id)
{
var cliente = db.Clients.Find(id);
return cliente != null ? Json(true) : Json(false);
}
Edit : And you have to replace your following code 编辑:并且您必须替换您的以下代码
@Html.ActionLink("Editar", "Edit", new { id=item.id })
with this code : 使用此代码:
<input class="button" type="button" value="Edit" onclick="validateForEdit(item.id)" />
Hope this help. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.