gpt4 book ai didi

c# - 如何设置 if checkbox checked 语句?

转载 作者:太空宇宙 更新时间:2023-11-03 20:36:36 25 4
gpt4 key购买 nike

我有多个动态复选框。我想找出 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com