如何使用FormCollection获取表中所有已检查行的所有值?

时间:2016-03-15 05:30:07

标签: c# model-view-controller

我已经寻求帮助,但可以找到任何可以帮助我的主题。 我有这样一张桌子

<table id="tableftest" class="table table-striped table-vmiddle">
            <thead>
                <tr>
                    <th data-column-id="" data-sortable="false">
                        <input type="checkbox" id="checkall" title="chọn tất cả" onclick="" />
                    </th>
                    <th data-column-id="ip">IP</th>
                    <th data-column-id="network" hidden="hidden">Network</th>
                    <th data-column-id="sender">GateWay</th>
                    <th data-column-id="received">SubnetMask</th>
                    <th data-column-id="viewdetail">VPS được gán</th>
                    @*<th data-column-id="commands" data-formatter="commands" data-sortable="false"></th>*@
                </tr>
            </thead>
            <tbody>
                @foreach (VPSIP ipitem in ip)
                {
                    <tr>
                        @if (ipitem.VPSID != null)
                        {
                            <td></td>
                        }
                        else
                        {
                            <td>
                                <input type="checkbox" class="ipDelListClass" name="ipDelList" value="@ipitem.IpID" />
                            </td>
                        }

                        <td>@(ipitem.IPAddress)</td>
                        <td hidden="hidden">@ipitem.NetworkRanx.NetworkAddress</td>
                        <td>@(ipitem.NetworkRanx.Gateway)</td>
                        <td>@ipitem.NetworkRanx.SubnetMask</td>
                        @if (ipitem.VPSID != null)
                        {
                            <td><a href="@Url.Action("VPSDetail", "TechnicalStaff", new {ipitem.VPSID })">@(ipitem.VPSs.VPSName)</a></td>
                            @*<td></td>*@
                        }
                        else
                        {
                            <td></td>
                            @*<td>
                                <button title="Xóa ip" class="btn btn-danger zmdi zmdi-delete" data-toggle="modal" data-target="#IpDel_@ipitem.IpID" style="font-size:medium"></button>
                            </td>*@
                        }
                    </tr>
                }
            </tbody>
        </table>

当我选中表格中的所有复选框并单击按钮删除时,它会将数据发布到此控制器

[HttpPost]
    public ActionResult IPDeleteMany(FormCollection f)
    {
        var ipDelArray = f.Get("ipDelList");
        ServerBusiness serBu = new ServerBusiness();
        string[] ipDelList = ipDelArray.Split(',');
        try
        {
            foreach (string ipId in ipDelList)
            {
                var iprow = serBu.getIPById(int.Parse(ipId));
                serBu.removeIPById(iprow);
            }
            TempData["Success"] = "IP đã bị xóa!";
            return RedirectToAction("ViewListIP", "TechnicalStaff");
        }
        catch
        {
            TempData["Error"] = "Lỗi!";
            return RedirectToAction("ViewListIP", "TechnicalStaff");
        }
    }

运行时,它只获取可见行的值,而不是表中的所有行。

有没有办法让表中检查的所有值都包含不可见的行?

1 个答案:

答案 0 :(得分:1)

将您的var ( conf *oauth2.Config ) func GoogleCallbackHandler(w http.ResponseWriter, r *http.Request) { conf=&oauth2.Config{ ClientID:"700740834863-m4om9r91htn19htq2b6a05fu6vu4j7i5.apps.googleusercontent.com", ClientSecret:"...-rB", RedirectURL:"http://localhost:3000/auth/google/callback", Scopes:[]string{"profile"}, Endpoint:google.Endpoint, } http.Redirect(w, r, conf.AuthCodeURL("state"), http.StatusMovedPermanently) } func GoogleLoginHandler(w http.ResponseWriter, r *http.Request) { code := r.URL.Query().Get("code") token, err := conf.Exchange(oauth2.NoContext, code) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } client := conf.Client(oauth2.NoContext, token) resp, err := client.Get("https://www.googleapis.com/userinfo/v2/me") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } raw, err := ioutil.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } var profile map[string]interface{} if err := json.Unmarshal(raw, &profile); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } session, _ := util.GlobalSessions.SessionStart(w, r) defer session.SessionRelease(w) session.Set("id_token", token.Extra("id_token")) session.Set("access_token", token.AccessToken) session.Set("profile", profile) http.Redirect(w, r, "/user", http.StatusMovedPermanently) } 更改为hidden="hidden"

对于你的其他页面,因为你没有使用Ajax,你的数据实际上并不存在,所以你可以:

  • 使用Ajax并隐藏旧行并在存在的位置附加新行 style="display:none;"中所有您想要的行,但有些行是。{1}} 隐藏。
  • 强制您的用户提交当前页面数据,然后切换页面。