如何使用FormCollection获取表格中所有已检查行的所有值?
问题描述:
我已经寻找帮助,但可以找到任何可以帮助我的话题。 我有这样如何使用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");
}
}
当它运行时,它只能得到行的值这是可见的,而不是表中的所有行。
有无论如何获取表中检查的所有值包括不可见的行吗?
答
将您的hidden="hidden"
更改为style="display:none;"
。
而对于你的其他页面,因为你没有使用Ajax您的数据实际上并不存在,所以您可以:
- 使用Ajax和隐藏你的老行和追加地方存在 所有的新行您所需的行在您的
html
但是其中一些隐藏 。 - 强制用户提交当前页面数据,然后切换页面。
+0
所以这只是方法,我会考虑。非常感谢! –
+1
据我所知,你的欢迎@NguyễnMinhThành –
你使用Ajax还是将你的数据回传给服务器? –
我使用表单将数据发布到服务器 –
我应该使用ajax吗? –