这是我的观点:
@foreach(var action in Model.Category.Actions) {
<div class="action" style="margin-right: 30px;">
<input type="checkbox" class="chk-act" id="@action.Id" name="actionChk" />
<text>@action.Text</text>
</div>
}
和html Dom如下所示:
<input type="checkbox" class="chk-act" id="17" name="actionChk">
<input type="checkbox" class="chk-act" id="18" name="actionChk">
<input type="checkbox" class="chk-act" id="19" name="actionChk">
因此,我需要检查ID。当我尝试通过表单集合获取值时,按选中的复选框的长度返回了
on
的字符串数组:[HttpPost]
public ActionResult Index(FormCollection collection) {
var actions = collection.GetValues("actionChk");
return View();
}
你有什么建议?
最佳答案
您应该将值放在value
参数中
<input type="checkbox" class="chk-act" id="17" value="17" name="actionChk">
<input type="checkbox" class="chk-act" id="18" value="18" name="actionChk">
<input type="checkbox" class="chk-act" id="19" value="19" name="actionChk">
然后,在 Controller 中,您应该有一个名为
Ids
的actionChk
数组