2016-03-15 85 views
1

我已經尋找幫助,但可以找到任何可以幫助我的話題。 我有這樣如何使用FormCollection獲取表格中所有已檢查行的所有值?

<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="#[email protected]" style="font-size:medium"></button> 
          </td>*@ 
         } 
        </tr> 
       } 
      </tbody> 
     </table> 

表當我檢查表中的所有checkboxs並單擊按鈕刪除,將數據發佈到該控制器

[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"); 
     } 
    } 

當它運行時,它只能得到行的值這是可見的,而不是表中的所有行。

有無論如何獲取表中檢查的所有值包括不可見的行嗎?

+0

你使用Ajax還是將你的數據回傳給服務器? –

+0

我使用表單將數據發佈到服務器 –

+0

我應該使用ajax嗎? –

回答

1

將您的hidden="hidden"更改爲style="display:none;"

而對於你的其他頁面,因爲你沒有使用Ajax您的數據實際上並不存在,所以您可以:

  • 使用Ajax和隱藏你的老行和追加地方存在 所有的新行您所需的行在您的html但是其中一些隱藏 。
  • 強制用戶提交當前頁面數據,然後切換頁面。
+0

所以這只是方法,我會考慮。非常感謝! –

+1

據我所知,你的歡迎@NguyễnMinhThành –

相關問題