获取复选框值控制器 [英] Get Checkbox values to controller
本文介绍了获取复选框值控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的观点我试图让选中的复选框值,控制器在数据库中保存。
In the below view i'm trying to get the checked checkbox values to the controller for saving in the database.
<div class="editor-label">
<%: Html.LabelFor(model => model.Addresses) %>
</div>
<div class="editor-field">
<% foreach (var item in Model.Addresses)
{ %>
<input type="checkbox"
id="<%: item.addressID %>"
name="addressOption"
value="<%: item.addressID%>"/>
<label for="optionId"><%: item.address%></label>
<br />
<% } %>
</div>
<br />
<div class="editor-label">
<%: Html.LabelFor(model => model.Mobile) %>
</div>
控制器:
AdvanceClient cli = new AdvanceClient();
if (ModelState.IsValid)
{
cli.Mobile = Request.Form["Mobile"];
foreach (var item in Request.Form["Addresses"])
{
//here i need to get the checked checkbox values
}
}
我卡与得到选中的复选框的值
I'm stuck with getting the values of checked checkboxes
推荐答案
您可以获取以逗号分隔字符串的所有值:
You can get all values in comma separated string from :
var selectedValues = Request.Form["mySharedName"];
// This is now a comma separated list of values that was checked
你这将是:的Request.Form [addressOption]
然后用为
循环,你可以得到所有值后,
after then using for
loop you can get all values
这篇关于获取复选框值控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文