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