Sae*_*eid 5 asp.net-mvc formcollection razor asp.net-mvc-3
这是我的观点:
@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>
}
Run Code Online (Sandbox Code Playgroud)
而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">
Run Code Online (Sandbox Code Playgroud)
所以我需要检查ID.当我尝试通过表单集合获取值时,它返回了一个on
按已检查复选框长度的字符串数组:
[HttpPost]
public ActionResult Index(FormCollection collection) {
var actions = collection.GetValues("actionChk");
return View();
}
Run Code Online (Sandbox Code Playgroud)
你的建议是什么?
您应该将值放在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">
Run Code Online (Sandbox Code Playgroud)
然后,从控制器,您应该有一个Ids
named 数组actionChk
归档时间: |
|
查看次数: |
6070 次 |
最近记录: |