我有多个动态复选框。我想找出 Controller 中选中了哪个复选框。我怎么做?这就是我的。
HTML
foreach (var items in collection) {
...
<tr><td>
<input id = "checkbox<%= items.id%>" name ="Checkbox<%= items.id%>" />
</td></tr>
...
}
Controller
foreach (var item in CheckboxList) {
string id = item.id;
if (Collection.Request.Form["Checkbox" + id].ToString()) {
//do stuff...
}
}
最佳答案
只有选中的复选框才会返回到表单上。
if(Collection.Request.Form["Checkbox" + id] != null)
{
// Checked!
}
来自spec (4.01):
When a form is submitted, only "on" checkbox controls can become successful.
关于c# - 如何设置 if checkbox checked 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4807157/