更新 Asp.Net MVC 中的表

发布于 2024-09-01 12:25:58 字数 252 浏览 0 评论 0原文

我在页面上有表 [HTML 表],我想从表中删除记录,并在删除记录后更新表。

<%= Ajax.ActionLink("Delete Ajax", "PostTypeDelete",new { id = item.int_PostTypeId }, 
   new AjaxOptions{LoadingElementId="status"}) %>

我使用上面的代码,它工作正常(它删除记录),但它不更新表。

I have table [HTML Table] on page I want to delete record from table and also update table after deletion record.

<%= Ajax.ActionLink("Delete Ajax", "PostTypeDelete",new { id = item.int_PostTypeId }, 
   new AjaxOptions{LoadingElementId="status"}) %>

I used above code its working fine (it delete record) but it doesn't update table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2024-09-08 12:25:58

该操作需要返回表的新副本减去已删除的行,并且您需要将表的 id 作为 AjaxOptions 的一部分提供给扩展方法 (UpdateTargetId) 因此它知道要使用操作的响应替换哪个元素。

<%= Ajax.ActionLink("Delete Ajax",
                   "PostTypeDelete",new { id = item.int_PostTypeId }, 
                    new AjaxOptions
                    {
                            LoadingElementId="status",
                            UpdateTargetId="tableid"
                    }) %>

或者 - 如果始终呈现整个表,即,由于当前行被删除,您将永远不会出现新行 - 您可以省略返回表并拥有一个完成的处理程序,该处理程序只需从表中删除有问题的行。在这种情况下,您可能只想返回一个与当前行具有相同 id 的空行,并在操作返回时使用处理程序将其删除。

The action needs to return a new copy of the table minus the deleted row and you need to give the id of the table to the extension method as part of the AjaxOptions (UpdateTargetId) so it knows which element to replace with the response from the action.

<%= Ajax.ActionLink("Delete Ajax",
                   "PostTypeDelete",new { id = item.int_PostTypeId }, 
                    new AjaxOptions
                    {
                            LoadingElementId="status",
                            UpdateTargetId="tableid"
                    }) %>

Alternatively -- if the entire table is always rendered, i.e., you will never have new rows appearing due to the current row being deleted -- you can omit returning the table and have a completed handler that simply removes the row in question from the table. In that case you might want to return just an empty row with the same id as the current row and use a handler to remove it when the action returns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文