【问题标题】:Adding check boxes to allow multiple Delete & edit from my html table添加复选框以允许从我的 html 表中进行多次删除和编辑
【发布时间】:2014-09-14 13:22:10
【问题描述】:

我的 asp.net mvc 视图中有下表:-

@foreach (var item in Model) {
    <tr id="@item.TMSServerID">
        <td>
            @Html.ActionLink("Edit", "Edit","Server", new { id=item.TMSServerID },null) |
            @if (!item.IsAlreadyAssigned()){ 

            @Ajax.ActionLink("Delete",
 "Delete", "Server",
new { id = item.TMSServerID },

new AjaxOptions
{ Confirm = "Are You sure You want to delete (" + item.Technology.Tag.ToString() + ")",
    HttpMethod = "Post",

    OnSuccess = "deletionconfirmation",
    OnFailure = "deletionerror"
})}
        </td>

        <td>
             @Html.ActionLink(item.Technology.Tag,"Details","Server",new { id = item.TMSServerID},null)
        </td>

        <td class="hidden-phone" >
            @item.status
        </td>

表格允许编辑,一次删除单个项目。但现在我想做以下事情:-

  1. 在每一行旁边添加一个复选框。

  2. 添加 Ajax 删除按钮以删除选定项

  3. 添加一个 Transfer ajax 按钮,允许编辑所选项目的状态。

所以我正在努力实现以下目标:-

  1. 如何使用 ajax 按钮传递项目 id + 项目时间戳字段,因为我需要检查所选项目是否已被其他用户修改?

  2. 如果删除操作成功,我如何从 html 表中删除选定的行?

谢谢

【问题讨论】:

标签: javascript jquery asp.net-mvc razor asp.net-mvc-5


【解决方案1】:

在表格的每个第一个单元格上添加一个复选框,并将 ModelID 作为每个复选框的值。

在你的 foreach 中,包含以下内容:

<td>
      <input type="checkbox" name="TMSServerID" value="1"  />
</td>

将此添加到控制器的 tha 参数中:Int32[] idList,如下所示:

  public void CheckForIds(Int32[] idList)
  {
     //Manipulate idList
  }

在您的按钮事件中,调用控制器方法。

您可能想看看这个以供参考:

http://byatool.com/mvc/asp-net-mvc-how-to-handle-multiple-checkboxes-with-viewsactions-jquery-too/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2013-07-11
    相关资源
    最近更新 更多