简体   繁体   English

如何在用户尝试编辑字段时向用户显示数据已消失?

[英]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.

相关问题 当他更新实体框架中的行时,如何检查用户是否是实体的所有者? - How can I check if user is owner of entity when he updates row in entity framework? 用户如何选择要在gridview中查看的数据 - how can user choose which data he want to view in gridview 当我需要向用户显示大量数据时,如何优化RAM使用? - How can I optimize RAM usage when I need to show user a large amout of data? 如何用ValueMember填充ComboBox编辑字段,但在列表中显示DisplayMember? - How can I populate ComboBox edit field with ValueMember but show DisplayMember in the list? 当用户向我的机器人发送消息时,他会收到欢迎消息。 但是,当用户对此做出响应时,机器人会再次发送欢迎消息。 我怎样才能解决这个问题? - When user sends message to my bot, he receives Welcome message. But when user respond to that, bot sends Welcome message again. How can I fix this? 在C#的文本字段中输入*字符时限制用户 - Restrict user when he enters * character in text field in c# 用户离线时如何在UWP中验证用户是否购买了订阅? - How can you verify in UWP if a user has purchased a subscription when he is offline? 用户共享联系人后如何保存用户的电话号码 - How can I save user's phone number after he shared his contact 用户注册时如何将数据保存到数据库中,即如何记住他在数据库中注册的数据? (给出错误) - How to save data to the database when the user registers, ie how to remember the data with which he registered in the database? (Give error) 当玩家接近航路点时,我将如何使其减速并再次加速? - How can i make that when the player is getting close to a waypoint he will slow down and then will speed up again?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM