5

これは私の見解です:

@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();
}

あなたの提案は何ですか?

4

1 に答える 1

10

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">

次に、コントローラーから、Ids名前付きの配列が必要です。actionChk

于 2012-03-28T12:11:55.763 に答える