【发布时间】:2012-12-31 21:42:22
【问题描述】:
我有一些图像,每个图像旁边都有一个复选框,如下所示:
<input type="checkbox" name="select" value="<%=item.Id%>" />
现在我想通过单击超链接将选定的复选框发送到控制器。我有:
<a href='<%: Url.Action("DeleteSelected", "Product", new { @ShopID = ViewBag.shopIDempty } ) %>'>Delete</a>
在控制器中:
public ActionResult DeleteSelected(int[] select, int ShopID)
{
foreach (int checkBoxSelected in select)
{
//Do something...
}
return RedirectToAction("Index");
}
但是没有任何东西传递给 int[] select 并且它始终为 null。怎么了?
【问题讨论】:
-
如果你想通过链接将参数传递给 DeleteSelected,你必须手动将选中的复选框值添加到链接参数中,否则你应该用表单包装复选框并使用按钮单击 POST 选中的项目
标签: asp.net-mvc checkbox