5
获取选中的复选框的IDS这是我的看法:在MVC3
@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();
}
你有什么建议吗?
由于浏览器将发布输入名称(actionChk)因为他们都是相同的名字,你会得到数组。为什么不打乱行动chk17,actionChk18等? – StuartLC 2012-03-28 12:06:43